I have enabled the AutoPostBack
property of one of my form's textboxes, which according to w3 schools should only trigger a postback when I press enter or tab.
I am also calling a __doPostBack()
on pageLoad, given a user's answer to a javascript prompt. When I do that, the Request.Form['__EventTarget']
is not what I set it to be in the call to __doPostBack
.
The real issue to me is that if I set the TextBox's AutoPostBack attribute to false, the problem with the pageload __doPostBack call goes away. This is not behavior I expected. Any ideas about what is causing the problem? Why would the AutoPostBack enabled have any influence?
Here is some of the code:
asp:TextBox runat="server" ID="userName" OnTextChanged="UpdateTable" AutoPostBack="true"
script type="text/javascript"
//![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]
/script
input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value=""
input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value=""
input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value=""
function jsPrompt(name) {
var ans = confirm('really follow ' + name + '?');
if (ans) {
__doPostBack('follow', name);
}
}
Then in the codebehind page:
if (Request.Form["__EventTarget"] == "follow")
followPerson(Request.Form["__EventArgument"]);
But, I keep getting that Request.Form["__EventTarget"]
is ","
, and I've stepped through the javascript in the debugger. Just before form.submit()
, the arguments are not ","