Can't find variable __doPostBack

  • I am programming my first asp.net site
  • To work with iPhone safari.

My code in default.aspx file:

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

      

In the backend.cs file default.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");
        }
    }

      

Full source page from Safari DESKTOP:

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

      

Problem:

It works fine on safari / chrome desktop, I type masi / pass and click the button and go to a new page, but on iPhone it gives me a javascript error in the console and does nothing.

it says: Javascript: undefined ReferenceError: Cannot find variable: __doPostBack

I have absolutely no idea what to do.

Update - Solution:

I accidentally removed some of the javascript I had in the header (which did almost nothing) and now it works fine.

+3


source to share


1 answer


The problem is that ASP.net is for unknown browsers ... for example iPhone. While it would be nice to assume that unknown browsers might be using javascript ... you can specify what capabilities the browser has in the web.config or machine.config section.

Check http://slingfive.com/pages/code/browserCaps/ updated browser config file for asp.net

Here is an example case to match GECKO based browsers (Netscape 6+, Mozilla / Firefox, ...)



Link: See 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>

      

+3


source







All Articles