We help IT Professionals succeed at work.

onclick javascript event not called on submit button

rohan_koudinya
rohan_koudinya used Ask the Experts™
on
Hi,
I am using an onclick javascript event on a submit button, but that is not getting executed!!
this code works fine in Mozilla but not in IE7 (am using the same code at several other pages where it works fine even in IE7)
here is the code:
buttonSavePassword.Attributes.Add("onclick ", "return VerifyXssCharacters('" + textBoxNewPassword.ClientID + "','" + textBoxVerifyNewPassword.ClientID + "','" + RM.GetString("InvalidPatternExpression") + "');");
i register this event in the page_load()
also when viewing the view source of the page the code for the button reads as:

<input type="submit" name="ctl00$C$buttonSavePassword" value="Save Changes" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$C$buttonSavePassword&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="ctl00_C_buttonSavePassword" class="button-mouseout" onmouseover="this.className='button-mouseover'" onmouseout="this.className='button-mouseout'" />

can somebody help!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
try remove extra space from Add function might be it will help you:

buttonSavePassword.Attributes.Add("onclick ", "return VerifyXssCharacters('

buttonSavePassword.Attributes.Add("onclick", "return VerifyXssCharacters('
Luis PérezSoftware Architect in .Net

Commented:
Another possible solution is to use a normal -not submit- button:

<input type="submit" ...
change for this:
<input type="button"

As you will call a javascript in the onclick method of the button, submit your form manually inside the javascript function if all validations passed:

document.forms[0].submit();

Author

Commented:
@muhannadyasir
i tried that but doesn't work!
might be possible that you included this function two times in you page.
VerifyXssCharacters
one in master page and second in Content page.
Akin DeluI’m a software engineer, tech enthusiast and UI/UX lover.

Commented:
why not use an asp button then add the javascript function to the OnClientClick property.
Chandramouli kArchitect

Commented:
name="ctl00$C$buttonSavePassword"
what is ctl100$C$?

Author

Commented:
@kcm76 this is the client id of the button!

Author

Commented:
got the answer