javascript function call from user control's command button
-
Hi all, I have a user control having a command button. On click of button, I've bound a javascript function which should show a div control. But, when I click on button, it postback the page. cmdPostComment.Attributes.Add("onClick", "return showDiv();") function showDiv() { document.getElementById("divPostComment_Tab1").style.display = "block"; return false; } I've noticed one thing, When page renders, command buttons name got changed to "control1$cmdPostComment". Thanks in advance.
-
Hi all, I have a user control having a command button. On click of button, I've bound a javascript function which should show a div control. But, when I click on button, it postback the page. cmdPostComment.Attributes.Add("onClick", "return showDiv();") function showDiv() { document.getElementById("divPostComment_Tab1").style.display = "block"; return false; } I've noticed one thing, When page renders, command buttons name got changed to "control1$cmdPostComment". Thanks in advance.
Add it as OnClientClick in your aspx page. That should work.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
-
Add it as OnClientClick in your aspx page. That should work.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
No luck
-
No luck
Do you have auto postback turned on ? I do this all the time and it works fine, set the OnClientClick, return false from it, and the Onclick will not run.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
-
Hi all, I have a user control having a command button. On click of button, I've bound a javascript function which should show a div control. But, when I click on button, it postback the page. cmdPostComment.Attributes.Add("onClick", "return showDiv();") function showDiv() { document.getElementById("divPostComment_Tab1").style.display = "block"; return false; } I've noticed one thing, When page renders, command buttons name got changed to "control1$cmdPostComment". Thanks in advance.
Neeraj Arora wrote:
document.getElementById("divPostComment_Tab1").style.display = "block";
Check the ID of "divPostComment_Tab1" after rendering of the page and use that ID instead of "divPostComment_Tab1".