Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below is my .aspx page

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CHEWGB.Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <style type="text/css">
        body {
            background-color: none;
        }

        .control-label {
            color: black;
            font-weight: 600;
            font-size: 17px;
            text-align: center;
            font: bolder;
        }

        .submitBtn {
            padding: 10px 20px 11px !important;
            font-size: 21px !important;
            background-color: orange;
            font-weight: bold;
            text-shadow: 1px 1px #F36C8C;
            color: black;
            border-radius: 100px;
            -moz-border-radius: 100px;
            -webkit-border-radius: 100px;
            border: 1px solid #F36C8C;
            cursor: pointer;
            box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
            -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
            -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
        }

            .submitBtn:hover {
                -webkit-transform: scale(1.3);
                transform: scale(1.3);
            }
    </style>

    <table style="background-color: none; border-collapse: separate; border-spacing: 20px; font: bold; font-size:larger">
        <tr>
            <td align="center">
                <asp:Label ID="Label1" runat="server" CssClass="control-label" Text="Enter Number : " BackColor="Aquamarine"></asp:Label>
            </td>
            <td align="center">
                <asp:TextBox ID="txtNumber" runat="server" autocomplete="off"></asp:TextBox>
            </td>
            <td align="center">
                <asp:Button ID="submtBtn" CssClass="submitBtn"  runat="server" Text="Submit" OnClick="submtBtn_Click" Style="float: right;" />
            </td>
        </tr>
    </table>

    <div id="dvProgressBar" style="float: left; visibility: hidden;">
        <img src="loading.gif" />
        Generating Pdf, please wait...
    </div>
  <br style="clear:both" />

    <link href = "Css/jquery-ui.css" rel = "stylesheet"/>
      <script src = "Scripts/jquery-1.10.2.js"></script>
      <script src = "Scripts/jquery-ui.js"></script>

      <script src = "Scripts/jquery.timepicker.min.js"></script>
      <script src = "Scripts/jquery.ui.timepicker.min.js"></script>
      <link href = "Css/jquery.timepicker.css" rel = "stylesheet"/>
      <link href = "Css/jquery.ui.timepicker.css" rel = "stylesheet"/>
    <script type="text/javascript">
      function ShowProgressBar() {
        document.getElementById('dvProgressBar').style.visibility = 'visible';
      }

      function HideProgressBar() {
        document.getElementById('dvProgressBar').style.visibility = "hidden";
        }

    </script>
</asp:Content>


Below is my code Behind function

 protected void submtBtn_Click(object sender, EventArgs e)
        {
submtBtn.Text = "Please Wait...";

Page.ClientScript.RegisterStartupScript(this.GetType(), "showloadingIcon", "ShowProgressBar()", true);

            some codes to generate pdf using itextsharp

Page.ClientScript.RegisterStartupScript(this.GetType(), "hideloadingIcon", "HideProgressBar()", true);

 submtBtn.Text = "Submit";
        }



The issue here is when i change the submtBtn text in code behind function it is not working and javascript function call for loading icon is also not working in code behind function.

What I have tried:

submtBtn.Text = "Please Wait...";

Page.ClientScript.RegisterStartupScript(this.GetType(), "showloadingIcon", "ShowProgressBar()", true);

            some codes to generate pdf using itextsharp

Page.ClientScript.RegisterStartupScript(this.GetType(), "hideloadingIcon", "HideProgressBar()", true);
Posted
Updated 18-Jun-20 4:51am
v2
Comments
F-ES Sitecore 18-Jun-20 10:30am    
RegisterStartupScript doesn't call your javascript, while your server-side code is running the output is being generated so nothing has been sent to the browser yet so your js doesn't exist. If you want to do something client side, then server-side, then client-side you're going to have to split your code up so that the pdf generation happens via an ajax call maybe.

1 solution

Client code - which means Javascript - isn't executed until the page is complete, and is sent to the browser as HTML for rendering. Registering a script just adds HTML (and JS) to the page data, including it in the HTML, and nothing else. There is no way to "call" a JS function on a client and get a reply, or even know that it will be executed, unless the function causes a call back to the Server - which effectively means a new page Load and the sending of HTML to a new page. (Even Ajax works the same, albeit will smaller chunks of HTML that a whole page.)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900