简体   繁体   中英

Postback with setTimeout function using wrong?

I use the old system, developed on framework 1.0, and running now on framework 2.0 Source code is:

<select name="DropDownList1" AutoPostBack="true" id="DropDownList1" runat="server">
  <option selected="selected" value="One">One</option>
  <option value="Two">Two</option
</select>

Generated html:

<select name="DropDownList1" onchange="javascript:setTimeout('__doPostBack(\'DropDownList1\',\'\')', 0)" id="DropDownList1">
  <option selected="selected" value="One">One</option>
  <option value="Two">Two</option>
</select>

Its not work until I remove quotes around __doPostBack. Why? I receive a javascript error 1032: Invalid character. How I make it work? Thanks!

Found here, after spent a hours to solve: https://groups.google.com/forum/#!topic/microsoft.public.scripting.vbscript/q_Yp5Ngczeo

Answer: If you include a VBScript code block before any other code block on an ASPX page, the following statement will fail in IE (and the error is far from obvious since it is untrappable and says only that there is an Invalid character on line 1, character 2):

"javascript:setTimeout('__doPostBack(\\'anyASPXcontrol\\',\\'\\')', 0)"

This is a bug in IE 6 and possibly earlier versions (I only have v6 to play with.) I do not know if it affects IE 7 as I have not installed that for testing lately. Note that even though the prefix of "javascript:" is used, the setTimeout function assumes it's calling a VBScript function, presumably because the first script block is a VBScript block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM