Several trick operations in javascript on the aspx page
Source: Internet
Author: User
1. In general, if you want to Add some javascript features to web form control on the aspx page, you can use Attributes. Add.
For example, for TextBox txt, you can:
Txt. Attributes. Add ("onclick", "fcn0 ();");
Then, when you click it on the web page, the javascript function fcn0 will be called.
1.1 The exception is the parsing of attributes that cannot be identified by the IDE.
For example, for a RadioButton rbt, the IDE cannot recognize the onclick attribute, so similar to the preceding statement,
Rbt. Attributes. Add ("onclick", "fcn1 (this );");
In. net framework 1.1
<Input type = radio id = rbt onclick = "fcn1 (this);">...
In. net framework 1.0
<Span onclick = "fcn1 (this);"> <input type = radio id = rbt>... </span>
Note that in fcn1, the object corresponding to this parameter is different. This is a subtle difference.
2. For HTML control, you need to do more.
When designing the aspx page, drag a web form control from the toolbar, for example, TextBox to the page, two things will happen:
I. One more sentence on the aspx page
<Asp: TextBox id = "TextBox1" style = "..." runat = "server" Width = "102px" Height = "25px"> </asp: TextBox>
2. code behind: one more sentence
Protected System. Web. UI. WebControls. TextBox TextBox1;
If it is html control, runat = "server" will not appear in the first sentence, but will not be automatically added in the second round.
Therefore, to access html control, you must
1. Add the runat = "server" attribute to the statements on the aspx page to become
<INPUT style = "..." type = "text" size = "9" id = "htxt" runat = "server">
II. Declaration displayed in code behind
Protected System. Web. UI. HtmlControls. HtmlInputText htxt;
Note that the id of the first sentence is the same as the variable name of the second sentence.
2.1. Note that the preceding System. web. UI. webControls. the html control corresponding to TextBox is System. web. UI. htmlControls. htmlInputText. The html tag is <INPUT type = "text">,
Correspondingly, the html control corresponding to the html tag <body> is
Public System. Web. UI. HtmlControls. HtmlGenericControl myBody;
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