gpt4 book ai didi

javascript - 找不到变量 __doPostBack

转载 作者:行者123 更新时间:2023-11-29 10:51:12 29 4
gpt4 key购买 nike

  • 我正在编写我的第一个 asp.net 网站
  • 在 iPhone safari 上工作。

我在 default.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>

在 default.aspx 的后端 .cs 文件中:

    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:错误不明确的ReferenceError:找不到变量:__doPostBack

我完全不知道该怎么做。

更新 - 解决方案:

我随机删除了 header 中的一点点 javascript(几乎什么都没做),现在它工作正常。

最佳答案

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

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

这是一个匹配基于 GECKO 的浏览器(Netscape 6+、Mozilla/Firefox 等)的案例

引用:this question and answer.

<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>

关于javascript - 找不到变量 __doPostBack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9838379/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com