Mikecat)
From: old cat ghost ideal
Here we provide you with some solutions that are often easy to use. I encapsulated some effects in a class library file.
Warning window
/// <Summary>
/// The alert dialog box is displayed on the server.
/// </Summary>
/// <Param name = "str_message"> message. For example, "cannot be blank! "</Param>
/// <Param name = "page"> page class </param>
Public void alert (string str_message, page)
{
Page. registerstartupscript ("", "<SCRIPT> alert ('" + str_message + "'); </SCRIPT> ");
}
Reload this warning window to make a control focus
/// <Summary>
/// The alert dialog box pops up on the server side, and the control gets focus
/// </Summary>
/// <Param name = "str_ctl_name"> obtain the focus Control ID value, for example, txt_name </param>
/// <Param name = "str_message"> message. For example, enter your name! "</Param>
/// <Param name = "page"> page class </param>
Public void alert (string str_ctl_name, string str_message, page)
{
Page. registerstartupscript ("", "<SCRIPT> alert ('" + str_message + "'); document. forms (0 ). "+ str_ctl_name + ". focus (); document. forms (0 ). "+ str_ctl_name + ". select (); </SCRIPT> ");
}
Confirmation dialog box
/// <Summary>
/// The confirm dialog box is displayed on the server.
/// </Summary>
/// <Param name = "str_message"> message, for example, "Are you sure you want to delete it! "</Param>
/// <Param name = "BTN"> hide the id value of the botton button, for example, btn_flow </param>
/// <Param name = "page"> page class </param>
Public void confirm (string str_message, string BTN, page)
{
Page. registerstartupscript ("", "<SCRIPT> If (confirm ('" + str_message + "') = true) {document. forms (0 ). "+ Btn + ". click () ;}</SCRIPT> ");
}
Reload confirmation dialog box, click OK to trigger a hidden button event, and click Cancel to trigger a hidden button event
/// <Summary>
/// The confirm dialog box pops up on the server, asking the user about the operations to be switched to, including the operations for "OK" and "cancel"
/// </Summary>
/// <Param name = "str_message"> A message is displayed. For example, if "data is added successfully, click \" OK \ "to enter 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. registerstartupscript ("", "<SCRIPT> If (confirm ('" + str_message + "') = true) {document. forms (0 ). "+ btn_redirect_flow + ". click ();} else {document. forms (0 ). "+ btn_redirect_self + ". click () ;}</SCRIPT> ");
}
Focus
/// <Summary>
/// Make the control focus
/// </Summary>
/// <Param name = "str_ctl_name"> obtain the focus Control ID value, for example, txt_name </param>
/// <Param name = "page"> page class </param>
Public void getfocus (string str_ctl_name, page)
{
Page. registerstartupscript ("", "<SCRIPT> document. forms (0 ). "+ str_ctl_name + ". focus (); document. forms (0 ). "+ str_ctl_name + ". select (); </SCRIPT> ");
}
The subform returns the primary form.
/// <Summary>
/// Name: Redirect
/// Function: The subform returns the primary form.
/// Parameter: URL
/// Return value: NULL
/// </Summary>
Public void redirect (string URL, page)
{
If (session ["ifdefault"]! = (Object) "default ")
{
Page. registerstartupscript ("", "<SCRIPT> Publish topics .doc ument. Location. href = '" + URL + "'; </SCRIPT> ");
}
}
Determines whether it is a number.
/// <Summary>
/// Name: isnumberic
/// Function: determines whether the input is a number.
/// Parameter: String otext: Source Text
/// Return value: bool true: false: No
/// </Summary>
Public bool isnumberic (string otext)
{
Try
{
Int var1 = convert. toint32 (otext );
Return true;
}
Catch
{
Return false;
}
}
Obtain the actual length of a string (including Chinese characters)
// Obtain 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 press enter on a control with a keydown event, it becomes a tab.
Public void tab (system. Web. UI. webcontrols. webcontrol)
{
Webcontrol. Attributes. Add ("onkeydown", "If (event. keycode = 13) event. keycode = 9 ");
}
If the index is exceeded during the deletion in the DataGrid page
Public void jumppage (system. Web. UI. webcontrols. DataGrid DG)
{
Int int_pageless; // defines the number of page jumps
// If the current page is the last page
If (DG. currentpageindex = DG. The PageCount-1)
{
// If there is only one page
If (DG. currentpageindex = 0)
{
// After deletion, the page is displayed on the current page.
DG. currentpageindex = DG. The PageCount-1;
}
Else
{
// If the last page contains only one record
If (DG. Items. Count % DG. pagesize = 1) | DG. pagesize = 1)
{
// After deleting the last record of the last page, the page should jump to the previous page
Int_pageless = 2;
}
Else // if the number of records on the last page is greater than 1, the records are still on the current page after the last page is deleted.
{
Int_pageless = 1;
}
DG. currentpageindex = DG. pagecount-int_pageless;
}
}
}
Frequently UsedCodeIf my level is limited, please point out any omissions!
Thank you hereYanhui and Hao (hbzxf)Fully supported!