使用jQuery脚本设置ASP.NET控件属性 [英] Setting ASP.NET control property using jquery script

查看:140
本文介绍了使用jQuery脚本设置ASP.NET控件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置asp.net控件属性的新值,当我选中一个复选框。

在我来说,我有RegularEx pressionValidator asp.net控制,当我勾选我会对属性新值的ErrorMessage和ValidationEx pression。

我想这code,但并没有和我一起工作。

请帮忙。

这是我的code:
.................................................. .............................

 <脚本SRC =JS / jQuery的-1.4.1.js类型=文/ JavaScript的>< / SCRIPT><脚本类型=文/ JavaScript的>    功能chkinput(){
        如果($('#<%= chkIntphoneHome.ClientID%GT;')是(':检查')){            $('#<%= REV_HomePhone.ClientID%GT;')ATTR('的ErrorMessage','新味精')。
            $('#<%= REV_HomePhone.ClientID%GT;')ATTR('ValidationEx pression','新EXP')。
        }
    } < / SCRIPT>
< ASP:复选框ID =chkIntMobileHome=服务器风格=的位置是:绝对的;顶部:200像素;
                    左:535px;文本=INTERNATION code的AutoPostBack =真
                    />
< ASP:文本框ID =txtHomePhone=服务器风格=顶:147px;左:543px;位置:绝对的;
                    高度:的22px;宽度:128像素>< / ASP:文本框>
                < ASP:RegularEx pressionValidator ID =REV_HomePhone=服务器的ErrorMessage =请输入有效的家庭电话
                    风格=的位置是:绝对的;顶部:177px;左:476px;宽度:226px;
                    显示=动态的ControlToValidate =txtHomePhone
                    ValidationEx pression =?\\ d {3} \\ D {3} \\ D {4}>< / ASP:RegularEx pressionValidator>


解决方案

您需要在code处理的背后,它不会工作,你正在做的方式。 jQuery将增加这些属性的页面已经被渲染之后,因此,到输出,有你的.NET控件没有影响。

编辑:建议,你可以用你的内容与一个UpdatePanel让你得到你可能希望有与jQuery的部分回发效果,可以再勾在UpdatePanel的OnLoad事件,看看它是否是一个ajaxRequest,并相应地更新你的页面。

I'm trying to set new value for asp.net control property when I check a checkbox.

In my case I have RegularExpressionValidator asp.net control and when I check the box I would have new value for the properties ErrorMessage and ValidationExpression.

I tried this code but did not work with me.

please help.

here is my code: ...............................................................................

<script src="js/jquery-1.4.1.js" type="text/javascript"></script>

<script type="text/javascript">

    function chkinput() {


        if ($('#<%=chkIntphoneHome.ClientID %>').is(':checked')) {

            $('#<%=REV_HomePhone.ClientID %>').attr('ErrorMessage', 'new msg');
            $('#<%=REV_HomePhone.ClientID %>').attr('ValidationExpression', 'new exp'); 
        }
    }

 </script>
<asp:CheckBox ID="chkIntMobileHome" runat="server" Style="position: absolute; top: 200px;
                    left: 535px;" Text="Internation Code" AutoPostBack="True"
                    />
<asp:TextBox ID="txtHomePhone" runat="server" Style="top: 147px; left: 543px; position: absolute;
                    height: 22px; width: 128px" ></asp:TextBox>
                <asp:RegularExpressionValidator ID="REV_HomePhone" runat="server" ErrorMessage="Please enter valid Home Phone"
                    Style="position: absolute; top: 177px; left: 476px; width: 226px;" 
                    Display="Dynamic" ControlToValidate="txtHomePhone"
                    ValidationExpression="\d{3}?\d{3}\d{4}"></asp:RegularExpressionValidator>

解决方案

You need to deal with that in the code behind, it wont work the way you are doing. jQuery will add those attributes after the page has been rendered, thus, to the output, having no effect on your .NET control.

Edit: suggestion, you can wrap your content with an updatePanel so you get the partial postback effect you might be wanting to have with jQuery, you can then hook the OnLoad event in the updatePanel and see if it is an ajaxRequest, and update your page accordingly.

这篇关于使用jQuery脚本设置ASP.NET控件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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