Common attributes in Asp.net

Source: Internet
Author: User
Request. urlreferrer. absoluteuri;
Obtain the absolute path of the last request URL of the client)
For example: Protected   Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
Hyperlink1.navigateurl
= Request. urlreferrer. absoluteuri;
}
}

Maintainscrollpositiononpostback = "true"
Gets or sets a value that indicates whether the user is returned to the same location in the browser on the client after sending the message back.
For example: <% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default. aspx. CS " Maintainscrollpositiononpostback = " True " Title = "" Inherits = " Test_default "   %>

Defaultbutton = "submitbutton"
Set the default from button
For example:<FormID= "Form1"
Defaultbutton
= "Submitbutton"
Defaultfocus
= "Textbox1"
Runat
= "Server">


Postbackurl = "~ /Test/search. aspx"
Set submission page
For example:
Default. aspx: < Form ID = "Form1" Runat = "Server" Defaultbutton = "Submitbutton" Defaultfocus = "Searchterm" >
< ASP: textbox ID = "Searchterm" Runat = "Server" > </ ASP: textbox > < BR />
< ASP: button ID = "Button2" Runat = "Server" Text = "Submitbutton" Postbackurl = "~ /Test/search. aspx"   /> < BR />
</ Form >

Search. CS: Protected   Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
Textbox searchterm
=   New Textbox ();
Searchterm
= (Textbox) page. previouspage. findcontrol ( " Searchterm " );
Response. Write (searchterm. Text );
}
}


Usesubmitbehavior:
Specify Button The control uses the client browser's submission mechanism or ASP. NET Sending back. By default, the value of this attribute is True , Resulting in Button Controls use the browser's submission mechanism. If False , Then ASP. NET Page framework adds client scripts to the page to send the form to the server.

When Usesubmitbehavior The property is False Control developers can use Getpostbackeventreference Method to return Button . Getpostbackeventreference The string returned by the method contains the text of the client function call, which can be inserted to the client for event processing.Program.

Instance: prevents multiple button submissions

< ASP: button ID = "Btnsumbit" Runat = "Server" Usesubmitbehavior = "False"
Onclientclick
= "This. value = 'sumbit '; this. Disabled = true ;" Text = "Sumbit" Onclick = "Btnsumbit_click"  
/>

Protected   Void Btnsumbit_click ( Object Sender, eventargs E)
{
System. Threading. thread. Sleep (
3000 );
Response. Write (datetime. Now. tostring ());
}

Onclientclick:
Obtains or sets the client script executed when a click event of a server control is triggered.
Example: Add a confirmation prompt to the delete column of the gridview. < ASP: gridview ID = " Gridview1 " Runat = " Server " Autogeneratecolumns = " False " >
< Columns >
< ASP: boundfield datafield = " Field name " Headertext = " Name "   />
< ASP: templatefield showheader = " False " >
< Itemtemplate >
< ASP: linkbutton ID = " Linkbutton1 " Runat = " Server " Causesvalidation = " False "  
Onclientclick
= ' <% # "Return confirm (\" are you sure you want to delete "+ eval (" field name ") +? \ ");" %> '
Commandname
= " Delete " Text = " Delete " > </ ASP: linkbutton >
</ Itemtemplate >
</ ASP: templatefield >
</ Columns >
</ ASP: gridview >

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.