ASP.NET webform error with JQuery Mobile



这是我使用JQuery移动与asp.net webform的努力。下面是我在Default中使用的代码。aspx页面。很简单的代码

下面是aspx页面的完整代码。

  <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title> Login</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js">
    </script>
</head>
<body>
    <form id="form1" runat="server">
  <!-- Start of first page -->
<div data-role="page" id="foo">
    <div data-role="header">
        <h1>Mobile Login</h1>
    </div><!-- /header -->
    <div data-role="content">   
        <table width="100%">
           <tr width="100%">
             <td width="30%" align="right" valign="middle">
               <asp:Literal ID="lblUserName" runat="server" Text="User Name"></asp:Literal>
             </td>
             <td width="50%">
               &nbsp;&nbsp;
                <input type="text" maxlength="20" id="UserName" style="width:50%;"  runat="server" />
             </td>
           </tr>
            <tr width="100%">
             <td width="50%"  align="right">
             <asp:Literal ID="Literal1" runat="server" Text="Password"></asp:Literal>
             </td>
             <td width="50%">
              &nbsp;&nbsp; <input type="text" maxlength="20" id="Password" style="width:50%;" runat="server" />
             </td>
           </tr>
            <tr width="100%">
             <td width="50%" align="right">
             </td>
             <td width="50%">
                <table width="100%">
                    <tr>
                      <td width="30%">
                        <asp:Button ID="btnLogin" runat="server" Text="Login"
                         OnClick="btnLogin_Click" />
                      </td>
                      <td width="30%">
                       <asp:Button ID="btnCancel" runat="server" Text="Cancel"  CssClass="ui-btn-active"
                         OnClick="btnCancel_Click" />
                      </td>
                      <td width="40%">
                      </td>
                    </tr>
                </table>
             </td>
           </tr>
        </table>        
    </div><!-- /content -->
    <div data-role="footer">
        <h4>
          @ All right reserved.
        </h4>
    </div><!-- /footer -->
</div><!-- /page -->
    </form>
</body>
</html>
现在在服务器端
  protected void btnLogin_Click(object sender, EventArgs e)
{
    Response.Redirect("Home.aspx",true);
}
protected void btnCancel_Click(object sender, EventArgs e)
{
    UserName.Value = "";
    Password.Value = ""; 
}

但是当我点击登录/取消按钮时,除了Url从

更改外,什么都没有发生

http://localhost: 2278/移动/default . aspx

http://localhost: 2278/移动/default . aspx #/移动/default . aspx

我的代码有什么问题?我不能从ASP访问服务器端功能吗?. NET服务器控件在JQuery移动?我知道它可以在MVC中做得更好,但在这种情况下,这不是我的选择。

请帮

这是因为。net默认将type="submit"添加到Button控件中。您需要将其设置为false,我也将CausesValidation设置为false,如下所示:

<asp:Button ID="btnLogin" runat="server" Text="Login"
OnClick="btnLogin_Click" CausesValidation="False" UseSubmitBehavior="False" />
但是,公平地说,我不会使用服务器端事件来导航按钮单击。您可以使用更简单的方法实现:
<a href="Home.aspx" data-role="button">Login</a>

. .当然,这是假设您在导航离开之前不需要执行任何其他服务器端操作。

最新更新