gpt4 book ai didi

javascript - 从 ASPX 后面的代码中显示/隐藏 div

转载 作者:行者123 更新时间:2023-11-28 05:17:09 26 4
gpt4 key购买 nike

我有以下 html 页面(带 Bootstrap ),按钮和进度如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestLoading.WebForm1" %>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="/css/bootstrap.min.css" rel="stylesheet" />
<title></title>
</head>
<body>
<form id="form1" runat="server">

<div>
<asp:Button ID="btnSend" runat="server" OnClick="btnSend_Click" Text="Send" Width="71px" CssClass="btn btn-info" style="display: inline"/>
<div class="progress" runat="server" id="loadingSend">
<div class="progress-bar progress-bar-info progress-bar-striped active" aria-valuemax="100" aria-valuemin="0" aria-valuenow="100" role="progressbar" style="display: none">
Loading...
</div>
</div>
</div>
</form>

我想在代码后面显示/隐藏进度条,我尝试过:

 private HttpWebRequest request;

protected void btnSend_Click(object sender, EventArgs e)
{
request = (HttpWebRequest)WebRequest.Create("http://localhost:65533/MyService.svc/");

request.Method = WebRequestMethods.Http.Get;
request.ContentType = "application/json";

HtmlControl control = FindControl("loadingSend") as HtmlControl;
control.Style.Add("display", "block");

request.BeginGetResponse(new AsyncCallback(FinishWebRequest), null);
}

void FinishWebRequest(IAsyncResult result)
{
StringBuilder sb = new StringBuilder();
request.EndGetResponse(result);

var response = (HttpWebResponse)request.GetResponse();

var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

HtmlControl control = FindControl("loadingSend") as HtmlControl;
control.Style.Add("display", "none");
}

但这对我不起作用,有什么建议吗?

谢谢

最佳答案

您可以简单地使 div runat="server"并在代码中显示隐藏。

<div id="divProgress" runat="server"  class="progress-bar progress-bar-info progress-bar-striped active" aria-valuemax="100" aria-valuemin="0" aria-valuenow="100" role="progressbar" style="display: none">
Loading...
</div>

在 C# 中

divProgress.Visible = false;

关于javascript - 从 ASPX 后面的代码中显示/隐藏 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40887275/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com