RegisterOnSubmitStatement not posting eventtarget

A

APA

I have registered a OnSubmit client script using the below statement:

ClientScript.RegisterOnSubmitStatement(this.GetType(), Guid.NewGuid().ToString(), "var retVal = validateForm(); return retVal;");


The validateForm() function is called properly and does all the validation that it's supposed to however when the page is posted back the submit
button's OnClick eventhandler is not fired. As soon as I take the OnSubmit script out then it works. I've seen some examples where you can replace
the __doPostBack function but I didn't think that was necessary since my OnSubmit code is being executed.

Should I use the replacement for the __doPostBack function in place of the OnSubmit code?
 
A

APA

OK, so I added this into the page script (through the RegisterClientScriptBlock method) and removed the OnSubmit code.


<script type="text/javascript" Language="JavaScript">

var netPostBack = __doPostBack;
__doPostBack = EscapeHtml;

function EscapeHtml(eventTarget, eventArgument){
var retVal = validateForm();
if(!retVal) return false;
return netPostBack (eventTarget, eventArgument);
}

</script>



This didn't do anything as the validateForm javascript function didn't get called but it did allow the button eventhandler to fire. Then I put the
OnSubmit code back in and the validateForm function got called but the button eventhandler did not fire.


Any ideas?
 
G

Guest

I have registered a OnSubmit client script using the below statement:

ClientScript.RegisterOnSubmitStatement(this.GetType(), Guid.NewGuid().ToString(), "var retVal = validateForm(); return retVal;");

hmm, not sure, but what retVal is returned?

And why not to use IsPostBack instead of waiting OnClick?
 
B

bruce barker

when you register a onsubmit function its placed before the the
_dopostback call. if your code executes a return the dopostback will not
be called and its the code that fills in the postback args.

change your code to:

ClientScript.RegisterOnSubmitStatement(
this.GetType(),
"submitvalidate",
"if (!validateForm()) return false;");

also you should not use a guid for code that should only appear once. if
you switch to ajax, you can use handlers instead.

-- bruce (sqlwork.com)
 
A

APA

Not sure I understand what your change did (or was supposed to do) but it still didn't work. Here is the script generated:


<script type="text/javascript">
<!--
function WebForm_OnSubmit() {
if(!validateForm()) return false;
return true;
}
// -->
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top