Asp.net| tips here to provide you with some usually easy to use the solution of the effect. I encapsulated some of the effects in a class library file.
Warning window
<summary>
Server-side Pop-up Alert dialog box
</summary>
<param name= "str_message" > Hint message, Example: "Cannot be empty!" </param>
<param name= "page" >page class </param>
public void Alert (String str_message,page Page)
{
Page. RegisterStartupScript ("", "<script>alert" (' +str_message+ ");</script>");
}
Overload this warning window to get the focus of a control
<summary>
Server-side Pop-up Alert dialog box, and the control gets focus
</summary>
<param name= "Str_ctl_name" > Get focus Control ID values, such as:txt_name</param>
<param name= "Str_message" > Message, Example: "Please enter your name!" </param>
<param name= "page" >page class </param>
public void Alert (string str_ctl_name,string str_message,page Page)
{
Page. RegisterStartupScript ("", "<script>alert (' +str_message+");d ocument.forms (0). " +str_ctl_name+ ". focus (); Document.forms (0). " +str_ctl_name+ ". Select ();</script>");
}
Overload confirmation dialog box, click OK to trigger a hidden button event, click Cancel to trigger a hidden button event
<summary>
Server-side Pop-up Confirm dialog box asking users to turn to those actions, including "OK" and "Cancel" actions
</summary>
<param name= "Str_message" > hint information, such as: "Successfully add data, click \ OK \" button to fill in the process, click \ cancel \ "Modify Data" </param>
<param name= "Btn_redirect_flow" > "OK" button ID value </param>
<param name= "btn_redirect_self" > "Cancel" button ID value </param>
<param name= "page" >page class </param>
public void Confirm (string str_message,string btn_redirect_flow,string btn_redirect_self,page Page)
{
Page. RegisterStartupScript ("", "<script> If" (Confirm (' +str_message+ ') ==true) {document.forms (0). " +btn_redirect_flow+ ". Click ();} Else{document.forms (0). " +btn_redirect_self+ ". Click ();} </script> ");
}
Get focus
<summary>
To have the control focus
</summary>
<param name= "Str_ctl_name" > Get focus Control ID values, such as:txt_name</param>
<param name= "page" >page class </param>
public void GetFocus (String str_ctl_name,page Page)
{
Page. RegisterStartupScript ("", "<script>document.forms (0)." +str_ctl_name+ ". focus (); Document.forms (0). " +str_ctl_name+ ". Select ();</script>");
}
Subform returns to the main form
<summary>
Name: redirect
Function: Subform returns to main form
Parameters: URL
return value: null
</summary>
public void Redirect (String url,page Page)
{
if (session["Ifdefault"]!= (object) "Default")
{
Page. RegisterStartupScript ("", "<script>window.top.document.location.href=" "+url+" ";</script>");
}
}
Judge whether it is a number
<summary>
Name: Isnumberic
Function: To determine whether the input is a number
Parameters: String Otext: Source text
return value: BOOL true: Yes false: No
</summary>
public bool Isnumberic (string otext)
{
Try
{
int Var1=convert.toint32 (otext);
return true;
}
Catch
{
return false;
}
}
Gets the actual length of the string (including Chinese characters)
Gets the actual length of the string ostring
public int Stringlength (string ostring)
{
Byte[] Strarray=system.text. Encoding.default. GetBytes (ostring);
int res=strarray.length;
return res;
}
Convert Carriage return to tab
When you hit enter on a control with a KeyDown event, it changes to tab
public void Tab (system.web. Ui. WebControls. WebControl WebControl)
{
WebControl. Attributes. ADD ("onkeydown", "if (event.keycode==13) event.keycode=9");
}
The DataGrid paging appears out of index if it is deleted
public void Jumppage (System.Web.UI.WebControls.DataGrid DG)
{
int int_pageless; Number of pages to define page jumps
If the current page is the last page
if (DG. CurrentPageIndex = DG. PAGECOUNT-1)
{
If there's only one page
if (DG. CurrentPageIndex = 0)
{
Page stops on current page after delete
Dg. CurrentPageIndex = DG. PageCount-1;
}
Else
{
If the last page has only one record
if (DG. Items.Count% DG. PageSize = 1) | | Dg. PageSize = 1)
{
When the last record of the last page is deleted, the page should jump to the previous page
Int_pageless = 2;
}
else//If the last page has a record number greater than 1, then the current page is still stopped after the last page is deleted
{
int_pageless = 1;
}
Dg. CurrentPageIndex = DG. pagecount-int_pageless;
}
}
}
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