473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

RegisterOnSubmitStatement not posting eventtarget

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

ClientScript.RegisterOnSubmitStatement(this.GetTyp e(), 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?
Feb 20 '07 #1
4 3047
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?


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

ClientScript.RegisterOnSubmitStatement(this.GetTyp e(),
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?
Feb 20 '07 #2
On Feb 20, 11:37 am, APA <buddy...@hotmail.comwrote:
I have registered a OnSubmit client script using the below statement:

ClientScript.RegisterOnSubmitStatement(this.GetTyp e(), 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?

Feb 20 '07 #3
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)
APA wrote:
I have registered a OnSubmit client script using the below statement:

ClientScript.RegisterOnSubmitStatement(this.GetTyp e(),
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?
Feb 20 '07 #4
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>


bruce barker wrote:
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)
APA wrote:
>I have registered a OnSubmit client script using the below statement:

ClientScript.RegisterOnSubmitStatement(this.GetTy pe(),
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?
Feb 20 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: Gandalf | last post by:
If I have a javascript function on my page that I wish to be called immediately before the form is submitted, using Page.RegisterOnSubmitStatement might seem the ideal method to use. However,...
1
by: MeDhanush | last post by:
Can sb pl tell me When & how do you use i) RegisterHiddenField() ii) Hidden field EVENTTARGET iii) Hidden fieldEVENTARGUMENT I noticed ii) and iii) in the form. Any docs pointing to this...
1
by: Cosimo Galasso | last post by:
I install the framework SP1 as descrbed in the following article ... but i still get the same problem. Any suggestion ? > Note on the bug: >...
1
by: anat | last post by:
I want to show a confirm message before the gridview delete a record in the event: of deleting. I put the following code and it shows the message twice. why? rotected void...
1
by: Brian Christensen | last post by:
Hi, Due to long periods during postbacks I'm experimenting on having a load screen. Best practice for this I have been unable to find so I hope someone here can point me in the right direction. I...
1
by: APA | last post by:
Well, I've figured out a way around this mess. I have no idea why it doesn't work the way I think it should but I do know how to get it to work. The scenario is that I have a form that has one...
44
by: Bruce Wood | last post by:
This subject has come up several times in this group over the last year. Several people in this group seem to feel strongly about this topic. Rather than derail other threads with this discussion,...
2
by: APA | last post by:
Why does adding code to the form submit function using the RegisterOnSubmitStatement method prevent the server side event handler for the submit button from firing? This is completely useless. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.