Tips for. net2.0 that you may not know

Source: Internet
Author: User

1. After submitting the page, keep the position of the scroll bar

You can add the maintainscrollpositiononpostback command to the page command.

 
<% @PageLanguage ="C #" Maintainscrollpositiononpostback ="True" Autoeventwireup ="True" Codefile ="..." Inherits ="..." %>

2. After loading the page, move the focus to a control. You only need to specify the defaultfocus attribute of the form.

 
<Form Id ="Frm" Defaultfocus ="Txtusername" Runat ="Server">...</Form>

3. Set the default button of form through the defaultbutton attribute, that is, the button triggered when you press ENTER

<Form Id ="Frm" Defaultbutton ="Btnsubmit" Runat ="Server">...</Form>

4. You can use the $ symbol to easily find the control using the findcontrol method.

 <  Form   Id =  "Form1"   Runat =  "Server"   Defaultfocus =  "Formvw $ txtname"  >      <  Div  >          <  ASP: formview   Id =  "Formvw"  Runat =  "Server"  >              <  Itemtemplate  > Name: <  ASP: textbox   Id =  "Txtname"   Runat =  "Server"                       TEXT =  '<% #Eval ("firstname") + "" + eval ("lastname ")%>'   />              </  Itemtemplate  >          </  ASP: formview  >      </ Div  >  </  Form  > 

In the preceding example, the defaultfocus attribute of form is used to specify the focus control for page loading. You can use the $ symbol to easily locate txtname.

You can also use the followingCodeTo easily find controls

 
Textbox TB =This. Findcontrol ("Form1 $ formvw $ txtname")AsTextbox;If(TB! =Null){// Access Textbox Control}

5. For more information about cross-Page Submission, see the original article.

6. Use a strong type to access members of the masterpage attribute. For more information, see the original article.

7. You can use the validationgroup property of the verification control to specify the group to which the verification control belongs, and specify the verification group to be activated in the validationgroup property of the button.

    form   id =  " form1 "  runat =   "server"    search text:    Asp: textbox   id =   "txtsearch"   runat =   "server"  />     Asp: requiredfieldvalidator   id =   "valsearch"   runat =   "server"   controltovalidate =   "txtsearch"   validationgroup =  " searchgroup " />     Asp  

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.