jquery generates code for ASP.net server controls _jquery

Source: Internet
Author: User
HTML is as follows
Copy Code code as follows:

<tr>
&LT;TD class= "Lefttd" style= "width:107px" > Additional amount </td>
&LT;TD style= "width:315px" ><asp:textbox id= "Txtextendmoney" text= "0" runat= "Server" ></asp:TextBox>
<asp:regularexpressionvalidator id= "Regextend" runat= "controltovalidate=" Txtextendmoney "Display=" The Dynamic "errormessage=" format is incorrect "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= "Not nullable" ></asp:RequiredFieldValidator></td>
&LT;TD class= "Lefttd" > Settlement method </td>
<td><asp:dropdownlist id= "Ddlpaytype" runat= "Server" ><asp:ListItem> cash </asp:ListItem>< Asp:listitem> Bank Transfer </asp:ListItem></asp:DropDownList></td>
</tr>
<tr>
&LT;TD class= "Lefttd" > Settlement account </td>
&LT;TD colspan= "3" ><asp:radiobuttonlist id= "Rdbpayaccountbank" runat= "server" repeatlayout= "Flow" ></ Asp:radiobuttonlist></td>
</tr>

The last RadioButtonList ListItem is "other account", and then the corresponding ASP.net server control is added after the election. Remove the control when you select another.

Increase

Introduce jquery, and then the following code

Copy Code code as follows:

/* Settlement Method * *
$ (": 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 "> Bank </label><input runat= ' server ' id= ' txtbanknew ' type= ' text '/><label style= ' Margin-left:6px;margin-right:4px "for=" Txtaccountnew "> Account </label><input type= ' text ' id= ' Txtaccountnew ' runat= ' server '/></span> ');
};
$ ("#txtBankNew"). focus (). Select ();
});
$ (": Radio:not (: Last)"). Bind ("click", Function () {
if ($ ("#txtBankNew"). Length>0) {
$ ("#span"). Remove ();
}
});

It is worth noting that if the control after the append is a server control, that is, the runat= "Server" property, the original single quote generator automatically becomes double quotes, and runat= "server" disappears. This is actually consistent with writing this DOM structure. NET Framework processing manually in the foreground. So open this page source file to see the following

Unfortunately, the server control still doesn't work ...

Or use a hidden server control to solve it-!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.