Display message on asp label by using Javascript.
-
Hi All, I am having an asp:label and an asp:Button at front end. what I would like to do is when user clicks the button on the web form, then the label displays some message, such as: "the file is loading, please wait". I know i need to use JavaScript to achieve this, but not quite sure how to do it. I would appreciate someone in here can help me. Thanks very much.
-
Hi All, I am having an asp:label and an asp:Button at front end. what I would like to do is when user clicks the button on the web form, then the label displays some message, such as: "the file is loading, please wait". I know i need to use JavaScript to achieve this, but not quite sure how to do it. I would appreciate someone in here can help me. Thanks very much.
AndieDu wrote:
Add
OnClientClick="UpdateLabelMessage()"
to button control. Then in Javascript, you need to do something like:function UpdateLabelMessage()
{
document.getElementById('lblMessage').text = "Message updated";
}P.S.: label id used in Javascript might change based on the design of your webpage, you can check viewsource to get exact id to use in JS.
-
Hi All, I am having an asp:label and an asp:Button at front end. what I would like to do is when user clicks the button on the web form, then the label displays some message, such as: "the file is loading, please wait". I know i need to use JavaScript to achieve this, but not quite sure how to do it. I would appreciate someone in here can help me. Thanks very much.
As you made your Label visible false, it wont render on the page and can not be made visible fron javascript. So better make it like
<asp:label ID="Label1" runat="server" text="Label" style="display:none;"></asp:label>
Now you would be able to show from javascript. Add onClientClick as Sandeep suggested like
OnClientClick="ShowLabel();"
and your js function would befunction ShowLabel()
{
document.getElementById("<%=Label1.ClientID %>").style.display='';
document.getElementById("<%=Label1.ClientID %>").innerHTML="Updated Text";
}Let me know for any query
Cheers!! Brij Check my latest Article :URL Routing with ASP.NET 4.0