jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何混合jQuery Mobile和ASP.NET大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用jQuery Mobile和ASP.NET 4.0 Webforms创建一个移动网站.我创建了一个初始登录页面(Default.aspX),其中按钮调用ajax JavaScript函数,该函数在后端调用页面方法,如下所示:

Default.aspx的

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="UCP.Default" %>
<!DOCTYPE html>
<html>
<head>
    <title>UA Cover Plus</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
</head>
<body>
    <!-- Login -->
    <div data-role="page" id="login">
        <div data-role="header" data-position="fixed">
           <h1>Login</h1>
            <a href="#Family" data-icon="gear" class="ui-btn-right" data-iconpos="notext" data-theme="b" >Options</a>
        </div>
       <div data-role="content" data-theme="a">   
            <input type="text" id="txtUserName" placeholder="Username" />
            <input type="password" name="passwordinput" id="txtpassword"  placeholder="password" value=""  />
            <a href="javascript:Authenticate();" data-role="button" data-icon="check" data-iconpos="right">Log Me In!</a>
       </div><!-- /content -->
    </div><!-- /page -->
</body>

Ajax JQuery函数

function Authenticate() {
    $.ajax({
        type: "POST",url: "Default.aspx/Authenticate",data: "{'name': '" + $('#txtUserName').val() + "','pass': '" + $('#txtpassword').val() + "'}",contentType: "application/json; charset=utf-8",dataType: "json",success: function (msg) {
            if (msg.d != '-1') {
                userId = msg.d;
                GetCustomisedConsole();
            } else {
                alert("Authentication Failed");
            }
        },error: function () {
            alert("Error :(");
        }
    });
};

Default.aspx.cs中的页面方法

[WebMethod]
    public static int authenticate(String name,String pass)
    {
        using (DbContext db = new DbContext())
        {
            var user = db.Users.Where(x => x.UserName == name && x.password == pass).SingLeorDefault();
            if (user != null)
            {
                return user.Id;
            }
            else
            {
                return -1;
            }
        }
    }

我的问题是,这是它的意图吗?我问这个是因为我在jQuery示例中看到了表单和提交的使用,我不知道如何在asp.net中实现.

解决方法

我正以同样的方式做事并且完美无缺.

请看一下这个例子

Invoking Server Methods Using Jquery

大佬总结

以上是大佬教程为你收集整理的如何混合jQuery Mobile和ASP.NET全部内容,希望文章能够帮你解决如何混合jQuery Mobile和ASP.NET所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。