MaxPageStateFieldLength attribute in 1.asp.net 2.0
In asp.net 2.0, viewstate can be forcibly transmitted in segments. The Page. MaxPageStateFieldLength attribute is used. You can set the maximum number of bytes for each Page Status field in viewstate. The format is as follows, which must be set in the WEB. CONFIG file:
<Pages maxPageStateFieldLength = "5"/>
Here, the viewstate is set to no more than 5 bytes. If the actual viewstate exceeds this value, multipart transmission is performed, but the size of each segment cannot exceed the value set in maxPageStateFieldLength, the default value is-1, indicating that segment transmission is not performed.
2. Click button only once in asp.net 2.0
1 protected void Page_Load (object sender, EventArgs e)
2 {
3 PostBackOptions options = new PostBackOptions (Button1, string. Empty );
4
5 StringBuilder sb = new StringBuilder ();
6 if (Button1.CausesValidation & this. GetValidators (Button1.ValidationGroup). Count> 0)
7 {
8 options. ClientSubmit = true;
9 options. Required mvalidation = true;
10 options. ValidationGroup = Button1.ValidationGroup;
11
12 sb. Append ("if (typeof (Page_ClientValidate) = 'function ')");
13 sb. Append ("if (Page_ClientValidate (\" "+ Button1.ValidationGroup +" \ ") = false) return false ;");
14}
15 if (! String. IsNullOrEmpty (Button1.PostBackUrl ))
16 options. ActionUrl = HttpUtility. UrlPathEncode (Button1.ResolveClientUrl (Button1.PostBackUrl ));
17
18 sb. Append ("this. disabled = true ;");
19 sb. Append (ClientScript. GetPostBackEventReference (options ));
20 sb. Append (";");
21 Button1.Attributes. Add ("onclick", sb. ToString ());
22}
3.asp.net 2.0 returns the number of rows returned by sqldatasource
In asp.net 2.0, the gridview is bound to the sqldatasource control. How can we get the number of records returned by sqldatasource? For example, in the sqldatasource control, how does one return the number of record rows? In. net 2.0, you can use the OnSelected event of sqldatasource, and set the AffectedRows attribute in the select event SqlDataSourceStatusEventArgs parameter. The core code is as follows:
Protected void sqldatasourceincluselected (object sender, SqlDataSourceStatusEventArgs e)
{
TotalRows. Text = e. AffectedRows. ToString ();
}
<Asp: SqlDataSource ID = "SqlDataSource1" runat = "server" ConnectionString = "Data Source = (local); Initial Catalog = Northwind; user id = sa; password = 123456; "ProviderName =" System. data. sqlClient "SelectCommand =" SELECT [CustomerID], [CompanyName], [ContactName] FROM [MERs] "OnSelected =" SqlDataSource1_Selected "> </asp: SqlDataSource>
4. in asp.net 1.1, javascript code may be used to set a control as the default focus button (that is, the default focus is on this control) on the page_load page, in ASP.. NET 2.0. In form code, use
The defaultbutton and defaultfocus attributes can be used, for example
<Form id = "Form1"
Defaultbutton = "BtnSubmit"
Defaultfocus = "TextBox1"
Runat = "server">
When the page is loaded, the default button is btnsubmit, and the focus is on texbox1 by default.
5.asp.net 2.0 dialog box
In asp.net 1.1, a pop-up dialog box is usually written in the server code as follows:
BtnClick. Attributes. Add ("onclick", "return confirm ('Are you sure? ');");
Now in ASP. NET 2.0, you only need to use the client code to pull and add an onclientclick.
<Asp: button id = "btnClick" runat = "server" OnClientClick = "return confirm ('Are you sure? '); "Text =" Button "> </asp: button>
5. Custom page controls,
For example, in ASP. . NET 1. 1, to declare a custom page control,
Generally, you need to add register prefix = ........ this is very troublesome, but in asp.net 2.0, if you are sure that a page custom control should be
Used in the entire project, you only need to add
<System. web>
<Pages>
<Controls>
<Add tagPrefix = "prefixname" namespace = "namespacename"/>
</Controls>
</Pages>
</System. web>
Prefixname indicates the control identifier and namespace indicates the namespace.