javascript-找不到变量__doPostBack
作者:互联网
>我正在编写我的第一个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('ctl00$MainContent$btnLogin','')">Log me in!</a>
</form>
</div>
</body>
</html>
问题:
它在桌面safari / chrome上可以正常工作,我键入masi / pass并按下按钮,然后转到新页面,但是在iPhone上,它在控制台中给了我一个javascript错误,什么也不做.
它说 :
Javascript:错误
未定义
ReferenceError:找不到变量:__doPostBack
我对如何做一无所知.
更新-解决方案:
我随机删除了标头中的少量javascript(几乎没有执行任何操作),现在可以正常使用了.
解决方法:
问题是ASP.net处理未知浏览器(例如iPhone)的默认方式.即使最好假设未知的浏览器可以使用javascript …,也可以在web.config或machine.config部分中指定浏览器具有的功能.
检出http://slingfive.com/pages/code/browserCaps/,获取asp.net的更新的browsercaps配置文件
这是匹配基于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>
标签:postback,asp-net,javascript,iphone,iui 来源: https://codeday.me/bug/20191201/2081793.html