Msdn: allows the Asp.net Server Control to issue client script blocks in the page. [C #]
Public Virtual void registerstartupscript (
String key,
String script
);
The parameter key identifies the unique key of the script block. The content of the script to be sent to the client. Here are some application instances: open a new window: page. registerstartupscript ("starup", "<script language = 'javascript '> window. open ('"+ URL +"', '', 'toolbar = No, resizable = Yes, scrollbars = yes') </SCRIPT>") 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 get the focus of a control. // <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> ");
} In the 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"> message, for example, "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> ");
} Get 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 main form. // <summary>
// Name: Redirect
// Function: The subform returns the main 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 = '/webjx/" + URL + "'; </SCRIPT> ");
}
}
Difference between page. registerclientscriptblock and page. registerstartupscript
---------------------------------------------------------------
Page. registerclientscriptblock
The script is placed in front of </form>.
Page. registerstartupscript
The script is placed next to the <form runat = "server"> followed by several hidden inputs.
If you just register some functions, the two functions have the same effect.
However, if you want to register some global scripts, such as defining some global variables and assigning values, the priority in HTML may be important, in this case, registerstartupscript should be used to ensure that the script can be executed before.