最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - ShowHide div from code behind ASPX - Stack Overflow

matteradmin7PV0评论

I have the follow html page (With bootstrap), With button and progress as follow:

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


<html xmlns="">
<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>

I want to show/hide the progress bar from code behind, What I'm tried:

 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");
    }

But this isn't working for me, Any suggestion?

Thanks

I have the follow html page (With bootstrap), With button and progress as follow:

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


<html xmlns="http://www.w3/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>

I want to show/hide the progress bar from code behind, What I'm tried:

 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");
    }

But this isn't working for me, Any suggestion?

Thanks

Share Improve this question asked Nov 30, 2016 at 11:31 EvyatarEvyatar 1,1573 gold badges14 silver badges38 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

You can simply make the div runat="server" and show hide in code.

<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>

In C#

divProgress.Visible = false;

What about to show your loading indicator on client side by reacting to OnClientClick button handler.

<asp:Button ID="btnSend" runat="server" OnClick="btnSend_Click" Text="Send" OnClientClick="onBeforeSend"/>

So after executing and returning result, refreshing page you can disable it again.

Post a comment

comment list (0)

  1. No comments so far