找不到变量__doPostBack

Can’t find variable __doPostBack

本文关键字:doPostBack 变量 找不到      更新时间:2023-09-26
    我正在
  • 编写我的第一个 asp.net 网站
  • 在iPhone野生动物园上工作。

我的代码默认.aspx正文:

<div id="pnlLogin" class="panel" selected="true" >
    <h2>Login Details</h2>
    <form ID="fLogin" runat="server" class="panel" selected="true" > 
        <fieldset>
            <div class="row">
                <label>Name</label>
                <asp:TextBox id="txtUserName" runat="server" placeholder="Your username" />
            </div>
            <div class="row">
                <label>Password</label>
                <asp:TextBox id="txtPassword" textmode="Password" runat="server" placeholder="Your password" />
            </div>
        </fieldset>
        <asp:LinkButton id="btnLogin" class="whiteButton" text="Log me in!" runat="server" onclick="Login_Clicked" />
    </form> 
</div>

在默认的后端.cs文件中.aspx

    protected void Login_Clicked(object sender, EventArgs e)
    {
        var username = txtUserName.Text;
        var password = txtPassword.Text;
        if (username == "masi" && password == "pass")
        {
            Response.Redirect("ControlPanel.aspx");
        }
    }

来自 DESKTOP Safari 的完整页面源代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head><title>
    Cover Plus
</title><meta id="viewport" name="viewport" content="width=device-width, user-scalable=0, initial-scale=1.0" /><link href="iui/iui.css" rel="stylesheet" type="text/css" /><link title="default" href="iui/t/default/default-theme.css" rel="stylesheet" type="text/css" />
        <script type="application/x-javascript" src="iui/iui.js"></script>

        <link rel="apple-touch-icon" href="img/touch-icon-iphone.png" /><link rel="apple-touch-icon" sizes="72x72" href="img/touch-icon-ipad.png" /><link rel="apple-touch-icon" sizes="114x114" href="img/touch-icon-iphone4.png" /><link rel="apple-touch-startup-image" href="img/startup.png" />
    <script type="text/javascript">
        function login()
        {
            var isVerified = Verify();
            if (isVerified) {
                ident.setAttribute("placeholder", "valid");
            }
        }
    </script>
</head>
    <body>

<div class="toolbar">
    <h1 id="pageTitle">Login</h1>
</div>
<div id="pnlLogin" class="panel" selected="true" >
    <h2>Login Details</h2>
    <form method="post" action="Default.aspx" id="fLogin" class="panel" selected="true">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTY2NzcyMzEwM2Rk+CbfIXzzsip63MXaBjBxcQhbraDzpmAHkc6FH4cZIiE=" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['fLogin'];
if (!theForm) {
    theForm = document.fLogin;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

<div class="aspNetHidden">
    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBALC/9DxDQKMrfuqAgKOsPfSCQKRnIq9D4GV4RtvQeooslP0bkLhJVOPoPu6Gt6b0rGrW9P8fPbK" />
</div> 
        <fieldset>
            <div class="row">
                <label>Name</label>
                <input name="ctl00$MainContent$txtUserName" type="text" id="MainContent_txtUserName" placeholder="Your username" />
            </div>
            <div class="row">
                <label>Password</label>
                <input name="ctl00$MainContent$txtPassword" type="password" id="MainContent_txtPassword" placeholder="Your password" />
            </div>
        </fieldset>
        <a id="MainContent_btnLogin" class="whiteButton" href="javascript:__doPostBack(&#39;ctl00$MainContent$btnLogin&#39;,&#39;&#39;)">Log me in!</a>
    </form> 
</div>
</body>
</html>

问题:

它在桌面 safari/chrome 上工作正常,我输入 masi/pass 并按下按钮并转到新页面,但在 iPhone 上,它在控制台中给了我一个 javascript 错误并且什么也不做。

它说:Javascript:错误定义引用错误: 找不到变量: __doPostBack

我完全不知道该怎么办。

更新 - 解决方案:

我随机删除了我在标题中的一点 javascript(几乎没有做任何事情(,现在它工作正常。

问题是 ASP.net 处理未知浏览器的默认方式......比如iPhone。即使假设未知的浏览器可以使用 javascript 会很好......您可以在 web.config 或 machine.config 部分中指定浏览器具有的功能。

查看 http://slingfive.com/pages/code/browserCaps/以获取更新的 browsercaps 配置文件 asp.net

以下是匹配基于GECKO的浏览器(Netscape 6+,Mozilla/Firefox等(的案例示例。

参考:本问答。

<case match="^Mozilla/5'.0 '([^)]*') (Gecko/[-'d]+)(?'VendorProductToken' (?'type'[^/'d]*)(['d]*)/(?'version'(?'major''d+)(?'minor''.'d+)(?'letters''w*)))?">
                    browser=Gecko
                    <filter>
                            <case match="(Gecko/[-'d]+)(?'VendorProductToken' (?'type'[^/'d]*)(['d]*)/(?'version'(?'major''d+)(?'minor''.'d+)(?'letters''w*)))">
                                    type=${type}
                            </case>
                            <case> <!-- plain Mozilla if no VendorProductToken found -->
                                    type=Mozilla
                            </case>
                    </filter>
                    frames=true
                    tables=true
                    cookies=true
                    javascript=true
                    javaapplets=true
                    ecmascriptversion=1.5
                    w3cdomversion=1.0
                    css1=true
                    css2=true
                    xml=true
                    tagwriter=System.Web.UI.HtmlTextWriter
                    <case match="rv:(?'version'(?'major''d+)(?'minor''.'d+)(?'letters''w*))">
                            version=${version}
                            majorversion=0${major}
                            minorversion=0${minor}
                            <case match="^b" with="${letters}">
                                    beta=true
                            </case>
                    </case>
            </case>