Loading Processing Window in Asp.net
Some functionalities in our systems takes some seconds to execute. In such case if you want to gray out the page and load a pop up window and close it when server side processing is done following code might help you.
aspx Code
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="jquery-1.8.2.min.js"></script>
- <script type="text/javascript">
- function eventInProgress() {
- $('#block').fadeIn();
- $('#container').fadeIn();
- }
- function CloseInprogressWindow() {
- $('#block').fadeOut();
- $('#container').fadeOut();
- }
- $(document).ready(function () {
- $('ul').css({ width: $('#container').width() - 20, height: $('#container').height() - 90 });
- });
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div id="block"></div>
- <div id="container">
- <h1>test....</h1>
- </div>
- <div>
- <asp:Button ID="btnSave" runat="server" Text="Button" OnClientClick="eventInProgress();" OnClick="btnSave_Click" />
- </div>
- </form>
- </body>
- </html>
Style Sheet
- * {
- font-family: Trebuchet MS;
- }
- #container {
- width: 30%;
- height: 10%;
- display: none;
- position: fixed;
- margin-top: 5%;
- margin-left: 5%;
- background: #FFF;
- border: 1px solid #666;
- border: 1px solid #555;
- box-shadow: 2px 2px 40px #222;
- z-index: 999999;
- }
- /*#container iframe {display:none; width: 100%; height: 100%; position: absolute; border: none; }*/
- #block {
- background: #000;
- opacity: 0.6;
- position: fixed;
- width: 100%;
- height: 100%;
- top: 0;
- left: 0;
- display: none;
- }
- ul {
- padding: 10px;
- background: #EEE;
- position: absolute;
- height: 200px;
- overflow: scroll;
- }
- ul li {
- color: #222;
- padding: 10px;
- font-size: 22px;
- border-bottom: 1px solid #CCC;
- }
- h3 {
- font-size: 26px;
- padding: 18px;
- border-bottom: 1px solid #CCC;
- }
Backend Code
- protected void btnSave_Click(object sender, EventArgs e)
- {
- System.Threading.Thread.Sleep(5000);
- CloseInprogressWindow();
- }
- private void CloseInprogressWindow()
- {
- string javaScript = "CloseInprogressWindow();";
- if (!ClientScript.IsStartupScriptRegistered("CloseInprogressWindow"))
- {
- ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseInprogressWindow", javaScript, true);
- }
- }
Output will Look Like below.
Hope this helps.
Happy Coding !!!!
Comments
Post a Comment