You may not know that. Net2.0 Tips

Source: Internet
Author: User
Tags eval access

1. After the page is submitted, keep the scroll bar position

You can add a maintainscrollpositiononpostback directive to the page instruction.

The following are the referenced contents:
<%@ Page language= "C #" maintainscrollpositiononpostback= "true" autoeventwireup= "true" codefile= "..." Inherits= "..."%>

2. After the page is loaded, move the focus to a control, just specify the form's DefaultFocus property.

The following are the referenced contents:
<form id= "frm" defaultfocus= "txtUserName" runat= "Server" >
...
</form>

3. Set the default corresponding button for the form through the DefaultButton property, that is, the button that fires when the user knocks in the carriage

The following are the referenced contents:
<form id= "frm" defaultbutton= "btnsubmit" runat= "Server" >
...
</form>

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

The following are the referenced contents:

<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 example above, use the DefaultFocus property of the form to specify the control in which the focus of the page is loaded, using the $ symbol to easily locate the Txtname

You can also use the following code to easily find the control

The following are the referenced contents:

TextBox TB = this. FindControl ("Form1$formvw$txtname") as TextBox;
if (TB!= null)
{
Access TextBox Control
}

5. About cross-page submissions the method of obtaining a strongly typed Submission page control is shown in the original

6. To access MasterPage property members using a strongly typed method, see the original

7. We can use the properties of the validation control ValidationGroup specify the group that the validation control belongs to, and specify the validation group that the button needs to activate in the ValidationGroup property of the button.

The following are the referenced contents:

<form id= "Form1" runat= "Server" >
Search Text: <asp:textbox id= "Txtsearch" runat= "Server"/>
<asp:requiredfieldvalidator id= "Valsearch" runat= "Server"
Controltovalidate= "Txtsearch" validationgroup= "Searchgroup"/>
<asp:button id= "btnsearch" runat= "Server" text= "Search"
validationgroup= "Searchgroup"/>
....
Controls with validators and buttons defined
</form>



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.