如何使用JQuery和Pagemethod获取选定的值 [英] How to get selected value using JQuery and Pagemethod

查看:85
本文介绍了如何使用JQuery和Pagemethod获取选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想使用pagemethod从c#中获取所选单选按钮的值,但它不起作用...
Html和JQuery代码:
< script type = text / javascript src = ../ javascripts / jquery-1.8.js > < < span class =code-leadattribute> / script >
< script type = text / javascript >
function scoreQuiz(form){
$(Save)。click(live,function(e){
e.preventDefault();
if(Page_ClientValidate()){
$ .checkSessionExists(function(event,data){
if(data.sessionExists){
PageMethods.Save(($('# <% = rbYesOne.ClientID %> ')。is(:checked),
function(){
alert(Selected);
});
else
window.location.href = urlpath +Login.aspx?returnurl = + encodeURI(MyProduct.aspx);
}
});
}
}
< / script >



< pre lang =xml> < / head < span class =code-keyword>>
< body >
< 表格 id = form1 runat = server >
< div >
< asp:RadioButton ID = rbYesOne value = 1 runat = server GroupName = Question1 / > < br / >
< asp:RadioButton ID = rbNoOne value = 0 runat = server GroupName = Question1 / > < < span class =code-leadattribute> br / >
< asp:按钮 文字 = 保存 runat = server / >
< / div >
< /表格 >
< / body >
< / html



>

 代码 file    c#代码:

[WebMethod(EnableSession = true)] / /
public 静态字符串保存(bool rdoYesTest)
{
HttpContext。当前 .Session [ rbYesOne] = rdoYesTest;
return HttpContext。当前 .Session [ rbYesOne]。ToString();
}

请有人帮忙解决此问题告诉我问题

解决方案

(保存)。点击(直播,功能(e){
e .preventDefault();
if(Page_ClientValidate()){


.checkSessionExists(function(event,data){
if(data.sessionExists){
PageMethods.Save((


('#<% = rbYesOne.ClientID %> ')。is(:checked),
function(){
alert(Selected);
});
else
window.location.href = urlpath +Login.aspx?returnurl =+ encodeURI(MyProduct.aspx);
}
});
}
}
< / script >



 <   / head  >  
< body >
< 表格 id = form1 runat = server >
< div >
< asp:RadioButton ID = rbYesOne value = 1 runat = server GroupName = Question1 / > < br / < span class =code-keyword>>
< asp:RadioButton ID = rbNoOne value = 0 runat = server < span class =code-attribute> GroupName = Question1 / > < br / >
< asp:按钮 文本 = 保存 runat = server < span class =code-keyword> / >
< / div >
< / form >
< / body >
< / html



>

和代码 file    c#代码:

[WebMethod(EnableSession = true)] //
public static string 保存(bool rdoYesTest)
{
HttpContext。当前 .Session [ rbYesOne] = rdoYesTest;
return HttpContext。当前 .Session [ rbYesOne]。ToString();
}

请有人帮忙解决此问题告诉我问题


Hi,
I want to get the value of a selected radiobutton from c# using a pagemethod but It is not working...
Html and JQuery code:
 <script type="text/javascript" src="../javascripts/jquery-1.8.js"></script>
    <script type="text/javascript">
        function scoreQuiz(form) {
            $("Save").click("live", function (e) {
                e.preventDefault();
                if (Page_ClientValidate()) {
                    $.checkSessionExists(function (event, data) {
                        if (data.sessionExists) {
                            PageMethods.Save(($('#<%=rbYesOne.ClientID%>').is(":checked"),
                                function(){
                                    alert("Selected");
                                });
                        else
                            window.location.href = urlpath + "Login.aspx?returnurl=" + encodeURI("MyProduct.aspx");
                    }
                });
            }
        }
    </script>


</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:RadioButton ID="rbYesOne" value="1" runat="server" GroupName="Question1" /><br />
    <asp:RadioButton ID="rbNoOne" value="0" runat="server" GroupName="Question1" /><br />
    <asp:Button Text="Save" runat="server" />
   </div>
    </form>
</body>
</html


>

and code behind file with c# code:

 [WebMethod(EnableSession = true)]//
    public static string Save(bool rdoYesTest)
    {
        HttpContext.Current.Session["rbYesOne"] = rdoYesTest;
        return HttpContext.Current.Session["rbYesOne"].ToString();
    }

Please can someone help fixing this and tell me what the problem is

解决方案

("Save").click("live", function (e) { e.preventDefault(); if (Page_ClientValidate()) {


.checkSessionExists(function (event, data) { if (data.sessionExists) { PageMethods.Save((


('#<%=rbYesOne.ClientID%>').is(":checked"), function(){ alert("Selected"); }); else window.location.href = urlpath + "Login.aspx?returnurl=" + encodeURI("MyProduct.aspx"); } }); } } </script>


</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:RadioButton ID="rbYesOne" value="1" runat="server" GroupName="Question1" /><br />
    <asp:RadioButton ID="rbNoOne" value="0" runat="server" GroupName="Question1" /><br />
    <asp:Button Text="Save" runat="server" />
   </div>
    </form>
</body>
</html


>

and code behind file with c# code:

 [WebMethod(EnableSession = true)]//
    public static string Save(bool rdoYesTest)
    {
        HttpContext.Current.Session["rbYesOne"] = rdoYesTest;
        return HttpContext.Current.Session["rbYesOne"].ToString();
    }

Please can someone help fixing this and tell me what the problem is


这篇关于如何使用JQuery和Pagemethod获取选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆