<!--page and profile--
1. Keep the scroll bar position after the page is submitted
You can add the MaintainScrollPositionOnPostBack directive to the page directive
<%@ page language= "C #" maintainscrollpositiononpostback= "true" autoeventwireup= "true" codefile= "..." Inherits= "..."%>
2. After the page is loaded, move the focus to a control, just specify the DefaultFocus property of the form.
<form id= "frm" defaultfocus= "txtUserName" runat= "Server" >
...
</form>
3. Set the default corresponding button of the form via the DefaultButton property, which is the button that is triggered when the user strikes a return
<form id= "frm" defaultbutton= "btnsubmit" runat= "Server" >
...
</form>
4. You can use the $ symbol to easily find a 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" &NBSP;
text= ' <%# eval ("FirstName") + "" + eval ("LastName")% > ' />
</ItemTemplate>
</asp:formview>
</div>
</ Form>
In the example above, the DefaultFocus property of the form is used to specify the control where the page is loaded with focus, and the $ symbol is used to easily locate the Txtname
You can also use the following code to easily find a control
TextBox TB = this. FindControl ("Form1$formvw$txtname") as TextBox;
if (TB! = NULL)
{
Access TextBox Control
}
5. About cross-page submissions the method of making a strong type of submit page control, see the original
6. To access the MasterPage attribute members using a strongly typed method, see the original
7. We can use the properties of the validation control ValidationGroup to specify which group the validation control belongs to, and specify the validation group that the button needs to activate 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:button id= "btnsearch" runat= "Server" text= "Search"
ValidationGroup = "Searchgroup" />
....
Other controls with validators and buttons defined here
</form>
This article is translated, the original address is as follows:
http://weblogs.asp.net/dwahlin/archive/2007/04/17/ Simple-asp-net-2-0-tips-and-tricks-that-you-may-or-may-not-have-heard-about.aspx