I need to clear the label status which is record saved after submitting button.
I used OnClientClick along with OnClick which is not working.
Below is the code:
<script type="text/javascript"
function clearLabelValue() {
var label1 = document.getElementById("<%= lblResults.ClientID %>");
label1.value ="";
}
Hi,
I need to clear the label status which is "record saved" after submitting button.
I used OnClientClick along with OnClick which is not working.
Below is the code:
<script type="text/javascript"
function clearLabel() {
var label1 = document.getElementById("<%= lblResults.ClientID %>");
label1.value ="";}
asp:Button ID="Button2" runat="server" Text="Submit" onclick="Button2_Click" OnClientClick="clearLabel()";return false;"/>
OnClientClick and onclick not working at the same time.I read some online posts and even tried by using ! before clearLabel().It is not working.
Alok UniyalPosted Mar 11, 2013, 2:47 AM
You can clear label text on Button2_Click.
protected void Button2_Click(object sender, EventArgs e)
{
/*Your code here*/
Label1.text=string.Empty;
}
sita kPosted Mar 12, 2013, 12:49 AM
Vishal GilbilePosted Mar 11, 2013, 2:18 AM
Whenever you are executing the javascript events along with the server side events then in this cases your javascript code executes first then your server side event code. I.e. your OnClientClick code will execute first as compared to that of your OnClick server event.
Well known solving your problem all you need to do is replace
var label1 = document.getElementById("<%= lblResults.ClientID %>");
label1.value ="";
with the following line of code.
document.getElementById('<%=lblResults.ClientID%>').innerHTML="";
Hope that solves your problem. If its solves kindly mark the answer as accepted, so that it may help other facing similar issue.
With Regards,
Vishal Gilbile.