Im working with Dreamweaver (these kind of problem never seems to happen with Visual.Studio...but anyway), and I want to use an asp control dropdownlist with the autopostback value to TRUE. But when I try to run it, my script debugger start, and nothing seems to work...why?
heres my dropdownlist:
<asp:DropDownList ID="cbbxTest" AutoPostBack="true" DataSource="<%# dsRegion.DefaultView %>" DataTextField="REGION_NAME" DataValueField="REGION_ID" runat="server"></asp:DropDownList>
and heres the error the script debugger gave me:
<script language="javascript" type="text/javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
theform = document._ctl3;
}
else {
theform = document.forms["_ctl3"];
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();<--this part in yellow, it seems the error happens here
}
// -->
</script>
so anybody know why this error occurs?? Thanks for taking the time to read this!
What is the id of your <form runat="server" tag? The default isForm1 normally, in which case, your javascript would look more likethis:theform = document.Form1;
and in fact, a better cross browser solution would be to use getElementById, like this:
theform = document.getElementById("Form1");
Anyway, I think your problem is that the element that you arereferencing is not the form element, and therefore doesn't have asubmit() method.
Good luck,
Sam
Is the web control enclosed within a form tag.
well it seems there was no ID in my form tag, only the name (which was form1), even though im not sure if it was really the problem. But still, I added one (id="form1") just to be sure, but I got the same error, the script debugger just gave me something more similar to your vision.
<script language="javascript" type="text/javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
theform = document.form1;
}
else {
theform = document.forms["form1"];
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();<--this part still in yellow
}
// -->
</script>
I will continue to search for the answer, but if you have others suggestions, dont hesitate to post them. And thanks for the first reply too!
and to sun (i was postong my other message at the same time you post yours, so I wasnt able to write a comment for you at the same time...wel depending on when the adminisatrtor will approve them of course), yest my web control is in a form tag, with runat="server" (Dreamweaver doesnt even allow me to create them if they're not between the form tag to begin with)
Try this before you call theform.submit();
alert(theform.action + "\n" + theform.method);
If you get an error there, the variable theform is not referencing your form element.
k, thanks, I will try that, but Monday, since the week is over, and im not in front of the computer wher my project is so...Anyway, thanks a lot for the advice.
Can we continue this thread please? I am receiving the same error. I have modified my __doPostBack method trying to get it to work to find out how to fix the aspx page itself. the alert dialog box with the action and method work just fine displaying the correct values. The line referenced by the error is bolded below. I don't understand why the error is above the alert that i see... All I am doing is changing the dropdown list, nothing else on the page.
<script language="javascript" type="text/javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
theform = document.form1;
}
/*else {
theform = document.forms["form1"];
alert("non microsoft");
}*/
alert(theform.__EVENTARGUMENT.value);
alert(eventArgument);
theform.__EVENTARGUMENT.value = eventArgument;
if (theform.submit) alert("submit"); else alert("no");
alert(theform.action + "\n" + theform.method);
theform.submit();
alert("set EVENTARGUMENT");
//theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
//theform.__EVENTARGUMENT.value = eventArgument;
//theform.submit();
};
// -->
</script>
Please Help, I'm so Lost!!
Wait... tell me again why you're modifying the doPostBack function?
We should probably go back to the original version and see what problems you have there.
Seeing as the thread has been dormant for 3 months, I suppose it is ok to hijack it! I have a webform that is developed, but the client wanted to add in another field, so I need a dropdownlist that auto posts back so that I can populate a 2nd dropdownlist. Setting the dropdownlist to autopostback="true" breaks things!
The javascript error points to theform.submit() in the __doPostBack function. As you can see I have been putting in various alert statements to verify the values are not null. Nothing errors in the function except for theform.submit(). I do have a submit button, and it does work correctly.
Borrowing from what someone else has already said in this thread, have you given your form tag a different ID attribute?
Also, you might consider going with a client-side dynamic solution instead of server-side (seethis post for some recommendations).
Cheers,
My form has the id "form1". All of the alert calls I added in the modified __doPostBack function I pasted above complete successfully, so that should verify for you that theform is being assigned properly.
I just finished implementing a callback solution from an article I found. ( http://dotnethero.com/hero/Selectionlists/Callback.aspx?nmx=6_4 )
While this solution works for this instance, I'm still very interested in why autopostback for a dropdownlist does not work and hope that people will continue to offer their suggestions.
I guess I was just confused because first you said the bolded line (with the eventargument assignment) was throwing the error, and then you said the form.submit line was the only one throwing an error.
Maybe if we knew what the error message said, we might have more useful input :)
The dialog that comes up references the bolded line. However, I verified each part of every statement with alerts that popped up successfully. The only line I can't piece apart is theform.submit() although if (theform.submit) alert("submit exists"); does print out.
The error is the object expected message.
Wow I am an idiot. I just solved this problem. The postback method calls theform.submit(); ... my asp:button had id="submit" ... once I changed the name of the button it works fine.
0 comments:
Post a Comment