[ASP. NET] methods frequently used in work

Source: Internet
Author: User

1. Add a confirmation prompt to the delete button:
Foreground method: onclientclick = "return window. Confirm ('Are you sure you want to delete it? ')"
Background method: btndelete. Attributes. Add ("onclick", "Return confirm ('Are you sure you want to delete it? ');");
2. Values in Dataset:
Lbltitle. Text = Ds. Tables [0]. Rows [0] ["title"]. tostring ();

3. String truncation method:
Public String stringformat (INT Len, string Str)
{
Return (Str. length> Len )? Str. substring (0, Len) + "...": STR;
}
4. Obtain the control in the gridview in the gridview event:
Linkbutton lbtnmanager = E. Row. findcontrol ("lbtnmanager") as linkbutton;

5. Obtain the ID of the primary key in datakeynames of the gridview:
Int id = convert. toint32 (sender as gridview). datakeys [E. Row. rowindex]. value. tostring ());
6. viewstate application:
[Disable viewstate at the front-end of the website; of course, it is best not to use PostBack]
Public String vsename
{
Get
{
If (enableviewstate)
{
Object OBJ = viewstate ["ename"];
If (OBJ! = NULL)
Return (string) OBJ;
Else
Return string. empty;
}
Else
Return string. empty;
}
Set
 

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.