Example of adding scripting code to an ASPX page by customizing the class
Source: Internet
Author: User
Script | page Set the initialfocus for a asp.net webform
The Pageutil class has a static method Setinitialfocus (control) which can is used to generate a JavaScript for a asp.net Page (WebForm), which sets the focus in a (given) control.
private void Page_Load (object sender, System.EventArgs e)
{
Set the Initialfocus on TextBox1
Pageutil.setinitialfocus (TextBox1);
Using System;
Using System.Web.UI;
Namespace Initialfocusdemo
{
<summary>
Utility class for a asp.net page
</summary>
public class Pageutil
{
<summary>
Set the Intialfocus to the given control. Only works as JavaScript is supported.
</summary>
<param name= ' control ' >control to set the Initialfocus on.</param>
public static void Setinitialfocus (Control control) {
if (control. Page = = null) {
throw new ArgumentException ("The control must is added to a Page before your can set the Intialfocus to it.");
}
if (control. Page.Request.Browser.JavaScript = = True) {
Control. Page.registerclientscriptblock ("Initialfocus",
"<script for= ' window ' event= ' onload ' language= ' JScript ' >document.all."
+ Control. UniqueID + ". Focus ();</script>");
}
}
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