Small function points collected in asp.net 2.0

Source: Internet
Author: User
asp.net Maxpagestatefieldlength Properties in 1.asp.net 2.0
In asp.net 2.0, you can force viewstate to be segmented and use the Page.maxpagestatefieldlength property to set the maximum number of bytes per page state field in ViewState. The format is as follows, to be set in the Web.config file:
<pages maxpagestatefieldlength= "5"/>
Where the setting is set to ViewState to no more than 5 bytes, and if the actual viewstate exceeds the value, a segmented transfer is performed, but the size of each fragment is still not greater than the set value in Maxpagestatefieldlength, the default setting is-1, Indicates that it is not staged for transmission.
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. Performvalidation = true;
Ten options. ValidationGroup = Button1.validationgroup;
11
SB. Append ("if (typeof (page_clientvalidate) = = ' function ')");
SB. Append ("If" (Page_clientvalidate (\ "" + Button1.validationgroup + "\") ==false) return false; ");
14}
if (!string. IsNullOrEmpty (Button1.postbackurl))
Options. ActionURL = Httputility.urlpathencode (Button1.resolveclienturl (Button1.postbackurl));
17
SB. Append ("this.disabled = true;");
SB. Append (Options) (clientscript.getpostbackeventreference);
SB. Append (";");
BUTTON1.ATTRIBUTES.ADD ("onclick", sb.) ToString ());
22}
Number of rows returned by SqlDataSource in 3.asp.net 2.0
In ASP.net 2.0, the GridView is bound to the SqlDataSource control, so how do you get the number of rows returned by SqlDataSource? For example, SqlDataSource controls use the SELECT * from ..., how do I return the number of rows it records? In. NET 2.0, you can implement it through the SqlDataSource Onselected event, and set the AffectedRows property in the Select event SqlDataSourceStatusEventArgs parameter. The specific core code is as follows:
protected void sqldatasource1_selected (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 [ Customers] "onselected=" sqldatasource1_selected "></asp:SqlDataSource>
4. In ASP.net 1.1, when you want to set a control as the default Focus button in the Page_Load page (that is, the default focus is on the control), you might want to use JavaScript code, and in ASP.net 2.0, you don't have to bother In the form code, use the
DefaultButton and DefaultFocus properties are OK, like
<form id= "Form1" defaultbutton= "Btnsubmit" defaultfocus= "TextBox1" runat= "Server" >
The default button button is btnsubmit when the page loads, and the focus defaults to the Texbox1.
Pop-up dialog box in 5.asp.net 2.0 In asp.net 1.1, the 1 pop-up dialogs are typically written in the server-side code:
BTNCLICK.ATTRIBUTES.ADD ("onclick", "Return to confirm (' Are you sure? ');"); Now in ASP.net 2.0, just use the client code to pull, a new onclientclick, so write
<asp:button id= "Btnclick" runat= "onclientclick=" return confirm (' Are for you sure? '); "text= button" ></ Asp:button>
5. Custom page controls,
For example, in ASP. NET 1. In 1, to declare a custom page control,
The register prefix= is usually added to every page you use ... Such, very troublesome, while in ASP.net 2.0, if you are certain that a page custom control is to be
For the entire project, just add it to the web.config.
<system.web>
<pages> <controls> <add tagprefix= "Prefixname" namespace= "NamespaceName"/> </controls> </pages></system.web>
Where Prefixname is the identity of the control, namespace is a namespace. <controls> <add tagprefix= "Prefixname" namespace= "NamespaceName"/> </controls> </pages> </system.web>
Where Prefixname is the identity of the control, namespace is a namespace.


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.