Jquery generates the Asp.net Server Control Code

Source: Internet
Author: User

The HTML is as follows: CopyCode The Code is as follows: <tr>
<TD class = "lefttd" style = "width: 0000px"> additional amount </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 = "Incorrect format" 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 = "cannot be blank"> </ASP: requiredfieldvalidator> </TD>
<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>
<TD class = "lefttd"> settlement account </TD>
<TD colspan = "3"> <asp: radiobuttonlist id = "rdbpayaccountbank" runat = "server" repeatlayout = "flow"> </ASP: radiobuttonlist> </TD>
</Tr>

The listitem of the last radiobuttonlist is "Other accounts". When elected, the corresponding Asp.net Server Control is added. Remove the control when selecting another one.

Add

Introduce jquery and then use the following code:

Copy code The Code is 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 account </label> <input runat = 'server' id = 'txtbanknew' type = 'text'/> <label style =" margin-left: 6px; margin-Right: 4px; "For =" txtaccountnew "> account opening </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 append is a server control with the runat = "server" attribute, the original single quotation marks will automatically become double quotation marks after being generated as the source, and runat = "server" disappears. This is actually consistent with the process of manually writing the DOM structure. NET Framework on the foreground. Open the source file on this page and you can see the following:

Unfortunately, the server control still does not work ......

You can hide the server control -!

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.