Msdn: allows the Asp.net Server Control to issue client script blocks in the page.
[C #]
Public Virtual void registerstartupscript (
String key,
String script
);
Parameters
Key
Unique key that identifies the script block.
Script
The content of the script to be sent to the client.
The following 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 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"> 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> ");
}
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 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> ");
}
}
From: http://blog.csdn.net/lee576/archive/2007/12/12/1931550.aspx
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/szuwangjl/archive/2009/07/20/4365001.aspx