jQuery生成asp.net服務(wù)器控件的代碼
更新時(shí)間:2010年02月04日 12:16:26 作者:
jQuery生成asp.net服務(wù)器控件 但不幸的是,該服務(wù)器控件依然沒有起作用,還是用隱藏服務(wù)器控件來解決吧
HTML如下
<tr>
<td class="leftTd" style="width: 107px">附加金額</td>
<td style="width: 315px"><asp:TextBox ID="txtExtendMoney" Text="0" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="regExtend" runat="server" ControlToValidate="txtExtendMoney" Display="Dynamic" ErrorMessage="格式不正確" ValidationExpression="[1-9]\d*\.\d*|0\.\d*[1-9]\d*|^[1-9]\d*|0"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="reqExtedNo" runat="server" ControlToValidate="txtExtendMoney" Display="Dynamic" ErrorMessage="不可為空"></asp:RequiredFieldValidator></td>
<td class="leftTd">結(jié)算方式</td>
<td><asp:DropDownList ID="ddlPayType" runat="server"><asp:ListItem>現(xiàn)金</asp:ListItem><asp:ListItem>銀行轉(zhuǎn)賬</asp:ListItem></asp:DropDownList></td>
</tr>
<tr>
<td class="leftTd">結(jié)算賬戶</td>
<td colspan="3"><asp:RadioButtonList ID="rdbPayAccountBank" runat="server" RepeatLayout="Flow"></asp:RadioButtonList></td>
</tr>
最后一個(gè)RadioButtonList的ListItem為“其他賬戶",當(dāng)選中時(shí),其后增加相應(yīng)的asp.net服務(wù)器控件。選擇其它時(shí)移除該控件。
/*結(jié)算方式*/
$(":radio:last").bind("click",function(){
if($("#txtBankNew").length==0){
$(this).parent().append('<span id="span"><label style="margin-left:6px;margin-right:4px;" for="txtBankNew">開戶銀行</label><input runat='server' id='txtBankNew' type='text' /><label style="margin-left:6px;margin-right:4px;" for="txtAccountNew">開戶賬戶</label><input type='text' id='txtAccountNew' runat='server' /></span>');
};
$("#txtBankNew").focus().select();
});
$(":radio:not(:last)").bind("click",function(){
if($("#txtBankNew").length>0){
$("#span").remove();
}
});
這里值得注意的是如果append之后的控件為服務(wù)器控件,也就是有runat="server"屬性的,原先的單引號生成源后會自動(dòng)變成雙引號,并且runat="server"消失。這實(shí)際上跟手工在前臺書寫此DOM結(jié)構(gòu).net framework處理一致。因此打開此頁面源文件可以看到如下

但不幸的是,該服務(wù)器控件依然沒有起作用……
還是用隱藏服務(wù)器控件來解決吧–!
復(fù)制代碼 代碼如下:
<tr>
<td class="leftTd" style="width: 107px">附加金額</td>
<td style="width: 315px"><asp:TextBox ID="txtExtendMoney" Text="0" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="regExtend" runat="server" ControlToValidate="txtExtendMoney" Display="Dynamic" ErrorMessage="格式不正確" ValidationExpression="[1-9]\d*\.\d*|0\.\d*[1-9]\d*|^[1-9]\d*|0"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="reqExtedNo" runat="server" ControlToValidate="txtExtendMoney" Display="Dynamic" ErrorMessage="不可為空"></asp:RequiredFieldValidator></td>
<td class="leftTd">結(jié)算方式</td>
<td><asp:DropDownList ID="ddlPayType" runat="server"><asp:ListItem>現(xiàn)金</asp:ListItem><asp:ListItem>銀行轉(zhuǎn)賬</asp:ListItem></asp:DropDownList></td>
</tr>
<tr>
<td class="leftTd">結(jié)算賬戶</td>
<td colspan="3"><asp:RadioButtonList ID="rdbPayAccountBank" runat="server" RepeatLayout="Flow"></asp:RadioButtonList></td>
</tr>
最后一個(gè)RadioButtonList的ListItem為“其他賬戶",當(dāng)選中時(shí),其后增加相應(yīng)的asp.net服務(wù)器控件。選擇其它時(shí)移除該控件。

增加

引入jQuery,然后如下代碼
復(fù)制代碼 代碼如下:
/*結(jié)算方式*/
$(":radio:last").bind("click",function(){
if($("#txtBankNew").length==0){
$(this).parent().append('<span id="span"><label style="margin-left:6px;margin-right:4px;" for="txtBankNew">開戶銀行</label><input runat='server' id='txtBankNew' type='text' /><label style="margin-left:6px;margin-right:4px;" for="txtAccountNew">開戶賬戶</label><input type='text' id='txtAccountNew' runat='server' /></span>');
};
$("#txtBankNew").focus().select();
});
$(":radio:not(:last)").bind("click",function(){
if($("#txtBankNew").length>0){
$("#span").remove();
}
});
這里值得注意的是如果append之后的控件為服務(wù)器控件,也就是有runat="server"屬性的,原先的單引號生成源后會自動(dòng)變成雙引號,并且runat="server"消失。這實(shí)際上跟手工在前臺書寫此DOM結(jié)構(gòu).net framework處理一致。因此打開此頁面源文件可以看到如下

但不幸的是,該服務(wù)器控件依然沒有起作用……
還是用隱藏服務(wù)器控件來解決吧–!
您可能感興趣的文章:
- ASP.NET自定義Web服務(wù)器控件之Button控件
- ASP.NET服務(wù)器端控件RadioButtonList,DropDownList,CheckBoxList的取值、賦值用法
- asp.net Page.EnableEventValidation 屬性驗(yàn)證服務(wù)器控件的回發(fā)和回調(diào)事件出現(xiàn)的錯(cuò)誤
- jquery獲取ASP.NET服務(wù)器端控件dropdownlist和radiobuttonlist生成客戶端HTML標(biāo)簽后的value和text值
- asp.net 服務(wù)器控件的 ID,ClientID,UniqueID 的區(qū)別
- asp.net下使用Request.From獲取非服務(wù)器控件的值的方法
- ASP.NET 動(dòng)態(tài)寫入服務(wù)器端控件
- asp.net Page.Controls對象(找到所有服務(wù)器控件)
- Asp.Net使用服務(wù)器控件Image/ImageButton顯示本地圖片的方法
相關(guān)文章
基于jquery的橫向滾動(dòng)條(滑動(dòng)條)
ASP.Net的GridView本身不帶滾動(dòng)條,可通過Panel實(shí)現(xiàn)。但是Windows自帶的橫向滾動(dòng)條只支持顯示在下方,為了使用方便,需要在上下方都顯示橫向滾動(dòng)條。2011-02-02
Jquery下的26個(gè)實(shí)用小技巧(jQuery tips, tricks & solutions)
前段時(shí)間發(fā)布了Jquery類庫1.4版本,使用者也越來越多,為了方便大家對Jquery的使用,下面列出了一些Jquery使用技巧。2010-03-03
jQuery實(shí)現(xiàn)的感應(yīng)鼠標(biāo)懸停圖片色彩漸顯效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)的感應(yīng)鼠標(biāo)懸停圖片色彩漸顯效果,涉及jQuery中hover、find、css等方法的使用技巧,需要的朋友可以參考下2015-03-03
當(dāng)jQuery遭遇CoffeeScript的時(shí)候 使用分享
雖然對ruby不太了解,但是看到CoffeeScript詩一般的代碼確實(shí)被怔住了,和jQuery之前給我的感覺是如此的相似——都是一個(gè)字,美,當(dāng)jQuery遭遇到CoffeeScript時(shí),會蹦出什么樣的火花呢?2011-09-09
jquery實(shí)現(xiàn)全選和全不選功能效果的實(shí)現(xiàn)代碼【推薦】
下面小編就為大家?guī)硪黄猨query實(shí)現(xiàn)全選和全不選功能效果的實(shí)現(xiàn)代碼【推薦】。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考2016-05-05
jquery通過load獲取文件的內(nèi)容并跳到錨點(diǎn)的方法
這篇文章主要介紹了jquery通過load獲取文件的內(nèi)容并跳到錨點(diǎn)的方法,涉及l(fā)oad及animate等方法的使用技巧,需要的朋友可以參考下2015-01-01
jQuery在IE下使用未閉合的xml代碼創(chuàng)建元素時(shí)的Bug介紹
這個(gè)偏門Bug是我在更新phZoom 1.29后發(fā)現(xiàn)的, 我先將之重現(xiàn)一下2012-01-01

