Postback from javascript

M

Martin Eyles

Thanks All, It's working nicely now.

ME

--
Martin Eyles
(e-mail address removed)
William F. Robertson said:
If you look carefully at the __doPostBack method that asp.net uses to post
back the page, you will see the functions sets two hidden text fields. The
hidden text fields are used to notify the processing page what control
caused the postback (for say a button click) and any parameters passed by
it.

Since you requirement is only a post back occured not caring about what
caused the postback, you can just call the submit method on the form object.

document.forms[0].submit();

This is the same method Microsoft uses to submit the form, and it will
accomplish what you are trying to accomplish with minimal effort.

bill

Martin Eyles said:
what should I put in the eventTarget and eventArgument variables? I can't
use a part of the form, as the postback is coming from a script (called from
another window), not the form. Note, I am not too bothered about working out
what caused post back, just that postback has occured.

ME

--
Martin Eyles
(e-mail address removed)

Kumar Reddi said:
Yeah, as William suggest, if you simply want to postback using javascript,
use document.forms[0].submit();. Or if you want to find out which control
caused the postback or to postback using a tradional non postback control,
then you can use the __doPostBack(). You do not have to make asp.net
generate the code, you can simply paste the following code. Thats exactly
what asp.net generate for you if you put linkbutton or whatever

<!--

function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
alert(theform.__EVENTARGUMENT.value);
theform.submit();
}
// -->

Also, for this code to work, you need to place the following two
hidden
html
controls on your form

<input type="hidden" name="__EVENTTARGET" />
<input type="hidden" name="__EVENTARGUMENT" />
 
G

Guest

You could simply do this:
document.formName.submit(); You won't have the overhead of calling the
overhead of calling the iterator on the 'forms' object (although its not
expensive).

- Shri

Martin Eyles said:
Thanks All, It's working nicely now.

ME

--
Martin Eyles
(e-mail address removed)
William F. Robertson said:
If you look carefully at the __doPostBack method that asp.net uses to post
back the page, you will see the functions sets two hidden text fields. The
hidden text fields are used to notify the processing page what control
caused the postback (for say a button click) and any parameters passed by
it.

Since you requirement is only a post back occured not caring about what
caused the postback, you can just call the submit method on the form object.

document.forms[0].submit();

This is the same method Microsoft uses to submit the form, and it will
accomplish what you are trying to accomplish with minimal effort.

bill

Martin Eyles said:
what should I put in the eventTarget and eventArgument variables? I can't
use a part of the form, as the postback is coming from a script (called from
another window), not the form. Note, I am not too bothered about working out
what caused post back, just that postback has occured.

ME

--
Martin Eyles
(e-mail address removed)

Yeah, as William suggest, if you simply want to postback using javascript,
use document.forms[0].submit();. Or if you want to find out which control
caused the postback or to postback using a tradional non postback control,
then you can use the __doPostBack(). You do not have to make asp.net
generate the code, you can simply paste the following code. Thats exactly
what asp.net generate for you if you put linkbutton or whatever

<!--

function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
alert(theform.__EVENTARGUMENT.value);
theform.submit();
}
// -->

Also, for this code to work, you need to place the following two hidden
html
controls on your form

<input type="hidden" name="__EVENTTARGET" />
<input type="hidden" name="__EVENTARGUMENT" />
 

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

Top