Disable web page calls Javascript
<SCRIPT lang = "text/JavaScript">
Window. Close ();
</SCRIPT>
Or: add this. button1.attributes. Add ("onclick", "window. Close ();") in page_load ();");
Obtain the focus. Create a new class in C #.
For example:
Sing system;
Using system. text;
Using system. Web;
Using system. Web. UI;
Namespace Application
{
/// <Summary>
/// Obtain the focus class
/// </Summary>
Public class focus
{
Public focus ()
{
}
// Set it to a static method. In this way, you do not need to create an instance object and call it directly in the form of focus. setfocus (this, "button2.
Public static void setfocus (system. Web. UI. Page, string m_focusedcontrol)
{
// If the control name is null, return
If (m_focusedcontrol = "")
Return;
// Add a script to declare a function
Stringbuilder sb = new stringbuilder ("");
SB. append ("<script language = JavaScript> ");
SB. append ("function ");
SB. append ("setfocusfunctionname ");
SB. append ("(CTL ){");
SB. append ("If (document. Forms [0] [CTL]! = NULL) "); // if it is not null, set the focus. The method in Javascript called here
SB. append ("document. Forms [0] [CTL]. Focus ();");
SB. append ("}");
// Add scripts to call Functions
SB. append ("setfocusfunctionname ");
SB. append ("('");
SB. append (m_focusedcontrol );
SB. append ("');");
SB. append ("</");
SB. append ("script> ");
If (! Page. isstartupscriptregistered ("setfocusscriptname "))
Page. registerstartupscript ("setfocusscriptname", SB. tostring (); // write this JavaScript code to the page.
}
/// <Summary>
/// Set the control that triggers the event when you press enter on the page
/// </Summary>
/// <Param name = "Ctrl"> control object that triggers the event </param>
Public static void setentercontrol (system. Web. UI. Control CTRL)
{
Page mpage = ctrl. page;
String mscript;
Mscript = @ "<script language =" "JavaScript" ">
Function document. onkeydown ()
{
VaR E = event. srcelement;
VaR K = event. keycode;
If (k = 13 & E. type! = "" Textarea "")
{
Document. All. "+ ctrl. clientid + @". Click ();
Event. cancelbubble = true;
Event. returnvalue = false;
}
}
</SCRIPT> ";
If (! Mpage. isclientscriptblockregistered ("setentercontrol "))
Mpage. registerclientscriptblock ("setentercontrol", mscript );
}
}
}
Add: Start pilot Import
Namespace
Using system. text;
Using system. Web. UI;
In the web page
You can call the methods in the focus class to obtain the focus in page_load (,) or in the button_click event.
I used the button_click time.
The Code is as follows:
// Textbox1 is the ID of the control to obtain the focus
Focus. setentercontrol (this. textbox1 );
Focus. setfocus (textbox1.page, "textbox1 ");