473,770 Members | 5,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp.net 2: Re-use code with ClientScript.Re gisterStartupSc ript

Hello,
I have the following sub in a class in my "App_Code" directory. The script
is for setting focus on a particular control, but I get the error,
"Name ClientScript Not declared". Also, I am using MasterPages. How do I
use "ClientScript.R egisterStartupS cript" in a class?

Public Shared Sub SetFocusControl (ByVal FocusControl As Control)

Dim Script As New System.Text.Str ingBuilder
Dim ClientID As String = FocusControl.Cl ientID
With Script
.Append("<scrip t language='javas cript'>")
.Append("docume nt.getElementBy Id('")
.Append(ClientI D)
.Append("').foc us();")
.Append("</script>")
End With
' ClientScript.Re gisterStartupSc ript(GetType(St ring), "ShowInfoPa ge",
Script.ToString ())

End Sub
Nov 19 '05 #1
7 4445
You need to do:

Me.Page.ClientS cript.RegisterC lienbtScriptBlo ck(...)

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hello,
I have the following sub in a class in my "App_Code" directory. The
script
is for setting focus on a particular control, but I get the error,
"Name ClientScript Not declared". Also, I am using MasterPages. How
do I
use "ClientScript.R egisterStartupS cript" in a class?
Public Shared Sub SetFocusControl (ByVal FocusControl As Control)

Dim Script As New System.Text.Str ingBuilder
Dim ClientID As String = FocusControl.Cl ientID
With Script
.Append("<scrip t language='javas cript'>")
.Append("docume nt.getElementBy Id('")
.Append(ClientI D)
.Append("').foc us();")
.Append("</script>")
End With
' ClientScript.Re gisterStartupSc ript(GetType(St ring),
"ShowInfoPa ge",
Script.ToString ())
End Sub

Nov 19 '05 #2
Thanks for Brock's suggestion.

Hi Sck10,

For Control class, we can access its container page instance through the
"Page" property. Also, if the control is dynamically created and added on
page, please make sure that before we access that Control.Page propety, the
control has been added into the Page's control structure , otherwise, the
"Page" property remains Nothing....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Message-ID: <b8************ **************@ msnews.microsof t.com>
| From: Brock Allen <ba****@NOSPAMd evelop.com>
| Subject: Re: asp.net 2: Re-use code with
ClientScript.Re gisterStartupSc ript
| References: <eJ************ **@TK2MSFTNGP09 .phx.gbl>
| MIME-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 671.6
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Date: Wed, 09 Nov 2005 14:49:00 -0800
| NNTP-Posting-Host: c-66-30-185-175.hsd1.ma.com cast.net 66.30.185.175
| Lines: 1
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3568 44
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| You need to do:
|
| Me.Page.ClientS cript.RegisterC lienbtScriptBlo ck(...)
|
| -Brock
| DevelopMentor
| http://staff.develop.com/ballen
|
| > Hello,
| > I have the following sub in a class in my "App_Code" directory. The
| > script
| > is for setting focus on a particular control, but I get the error,
| > "Name ClientScript Not declared". Also, I am using MasterPages. How
| > do I
| > use "ClientScript.R egisterStartupS cript" in a class?
| > Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
| >
| > Dim Script As New System.Text.Str ingBuilder
| > Dim ClientID As String = FocusControl.Cl ientID
| > With Script
| > .Append("<scrip t language='javas cript'>")
| > .Append("docume nt.getElementBy Id('")
| > .Append(ClientI D)
| > .Append("').foc us();")
| > .Append("</script>")
| > End With
| > ' ClientScript.Re gisterStartupSc ript(GetType(St ring),
| > "ShowInfoPa ge",
| > Script.ToString ())
| > End Sub
| >

|
|

Nov 19 '05 #3
Thanks Steve,

I'm still having problems. I get the following error when trying to use
"Me.Page". Also, I am only using "Imports Microsoft.Visua lBasic".

error: 'Me' is valid only within an instance method.

---------------------------------
Imports Microsoft.Visua lBasic

Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
Dim Script As New System.Text.Str ingBuilder
Dim ClientID As String = FocusControl.Cl ientID
With Script
.Append("<scrip t language='javas cript'>")
.Append("docume nt.getElementBy Id('")
.Append(ClientI D)
.Append("').foc us();")
.Append("</script>")
End With
'Me.Page.Client Script.Register ClienbtScriptBl ock(GetType(Str ing),
"SetFocusOnCont rol", Script.ToString ())
'Me.Page.Client Script.Register StartupScript(G etType(String),
"SetFocusOnCont rol", Script.ToString ())
End Sub
"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:SR******** ******@TK2MSFTN GXA02.phx.gbl.. .
Thanks for Brock's suggestion.

Hi Sck10,

For Control class, we can access its container page instance through the
"Page" property. Also, if the control is dynamically created and added on
page, please make sure that before we access that Control.Page propety, the control has been added into the Page's control structure , otherwise, the
"Page" property remains Nothing....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
-------------------- |
| You need to do:
|
| Me.Page.ClientS cript.RegisterC lienbtScriptBlo ck(...)
|
| -Brock
| DevelopMentor
| http://staff.develop.com/ballen

Nov 19 '05 #4
Thanks for your response Sck10,

What's the class of the "SetFocusContro l" method, from your code snippet ,
the "SetFocusContro l" method is a static function so that it can not access
its container class's "Me" property. In addition, only class derived from
System.Web.UI.C ontrol has the "Page" propety... Is this class only a
helper component class? If so, you need to use the passed in "Control"
parameter 's "Page" property to register the script, e.g:

=============== ==========
Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
Dim Script As New System.Text.Str ingBuilder
Dim ClientID As String = FocusControl.Cl ientID
With Script
.Append("<scrip t language='javas cript'>")
.Append("docume nt.getElementBy Id('")
.Append(ClientI D)
.Append("').foc us();")
.Append("</script>")
End With
FocusControl.Pa ge.ClientScript .RegisterClienb tScriptBlock(Ge tType(String),
"SetFocusOnCont rol", Script.ToString ())
............... ............... .....
=============== ======

Also, as I've mentioend in the former message, the "FocusContr ol" must
already been added into a certain page's control structure before we access
its "Page" property, otherwise, that property remains Nothing.

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "sck10" <sc***@online.n ospam>
| References: <eJ************ **@TK2MSFTNGP09 .phx.gbl>
<b8************ **************@ msnews.microsof t.com>
<SR************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: Re: asp.net 2: Re-use code with
ClientScript.Re gisterStartupSc ript
| Date: Thu, 10 Nov 2005 16:28:19 -0600
| Lines: 62
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <OB************ *@TK2MSFTNGP15. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: 189.202.185.135 .in-addr.arpa 135.185.202.189
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3572 02
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Thanks Steve,
|
| I'm still having problems. I get the following error when trying to use
| "Me.Page". Also, I am only using "Imports Microsoft.Visua lBasic".
|
| error: 'Me' is valid only within an instance method.
|
| ---------------------------------
| Imports Microsoft.Visua lBasic
|
| Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
| Dim Script As New System.Text.Str ingBuilder
| Dim ClientID As String = FocusControl.Cl ientID
| With Script
| .Append("<scrip t language='javas cript'>")
| .Append("docume nt.getElementBy Id('")
| .Append(ClientI D)
| .Append("').foc us();")
| .Append("</script>")
| End With
| 'Me.Page.Client Script.Register ClienbtScriptBl ock(GetType(Str ing),
| "SetFocusOnCont rol", Script.ToString ())
| 'Me.Page.Client Script.Register StartupScript(G etType(String),
| "SetFocusOnCont rol", Script.ToString ())
|
|
| End Sub
|
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:SR******** ******@TK2MSFTN GXA02.phx.gbl.. .
| > Thanks for Brock's suggestion.
| >
| > Hi Sck10,
| >
| > For Control class, we can access its container page instance through the
| > "Page" property. Also, if the control is dynamically created and added
on
| > page, please make sure that before we access that Control.Page propety,
| the
| > control has been added into the Page's control structure , otherwise,
the
| > "Page" property remains Nothing....
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
|
| > |
| > | You need to do:
| > |
| > | Me.Page.ClientS cript.RegisterC lienbtScriptBlo ck(...)
| > |
| > | -Brock
| > | DevelopMentor
| > | http://staff.develop.com/ballen
|
|
|

Nov 19 '05 #5
Hi Sck10,

Does the suggestions in my further response helps you? If there're anything
else we can help, please feel free to post here.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 32396961
| References: <eJ************ **@TK2MSFTNGP09 .phx.gbl>
<b8************ **************@ msnews.microsof t.com>
<SR************ **@TK2MSFTNGXA0 2.phx.gbl>
<OB************ *@TK2MSFTNGP15. phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online. microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Fri, 11 Nov 2005 01:44:44 GMT
| Subject: Re: asp.net 2: Re-use code with
ClientScript.Re gisterStartupSc ript
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| Message-ID: <m4************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 108
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3572 42
| NNTP-Posting-Host: tomcatimport2.p hx.gbl 10.201.218.182
|
| Thanks for your response Sck10,
|
| What's the class of the "SetFocusContro l" method, from your code snippet
,
| the "SetFocusContro l" method is a static function so that it can not
access
| its container class's "Me" property. In addition, only class derived
from
| System.Web.UI.C ontrol has the "Page" propety... Is this class only a
| helper component class? If so, you need to use the passed in "Control"
| parameter 's "Page" property to register the script, e.g:
|
| =============== ==========
| Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
| Dim Script As New System.Text.Str ingBuilder
| Dim ClientID As String = FocusControl.Cl ientID
| With Script
| .Append("<scrip t language='javas cript'>")
| .Append("docume nt.getElementBy Id('")
| .Append(ClientI D)
| .Append("').foc us();")
| .Append("</script>")
| End With
|
|
| FocusControl.Pa ge.ClientScript .RegisterClienb tScriptBlock(Ge tType(String),
| "SetFocusOnCont rol", Script.ToString ())
| ............... ............... .....
|
|
| =============== ======
|
| Also, as I've mentioend in the former message, the "FocusContr ol" must
| already been added into a certain page's control structure before we
access
| its "Page" property, otherwise, that property remains Nothing.
|
| Hope helps. Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
| --------------------
| | From: "sck10" <sc***@online.n ospam>
| | References: <eJ************ **@TK2MSFTNGP09 .phx.gbl>
| <b8************ **************@ msnews.microsof t.com>
| <SR************ **@TK2MSFTNGXA0 2.phx.gbl>
| | Subject: Re: asp.net 2: Re-use code with
| ClientScript.Re gisterStartupSc ript
| | Date: Thu, 10 Nov 2005 16:28:19 -0600
| | Lines: 62
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| | Message-ID: <OB************ *@TK2MSFTNGP15. phx.gbl>
| | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: 189.202.185.135 .in-addr.arpa 135.185.202.189
| | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:3572 02
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | Thanks Steve,
| |
| | I'm still having problems. I get the following error when trying to use
| | "Me.Page". Also, I am only using "Imports Microsoft.Visua lBasic".
| |
| | error: 'Me' is valid only within an instance method.
| |
| | ---------------------------------
| | Imports Microsoft.Visua lBasic
| |
| | Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
| | Dim Script As New System.Text.Str ingBuilder
| | Dim ClientID As String = FocusControl.Cl ientID
| | With Script
| | .Append("<scrip t language='javas cript'>")
| | .Append("docume nt.getElementBy Id('")
| | .Append(ClientI D)
| | .Append("').foc us();")
| | .Append("</script>")
| | End With
| | 'Me.Page.Client Script.Register ClienbtScriptBl ock(GetType(Str ing),
| | "SetFocusOnCont rol", Script.ToString ())
| | 'Me.Page.Client Script.Register StartupScript(G etType(String),
| | "SetFocusOnCont rol", Script.ToString ())
| |
| |
| | End Sub
| |
| |
| | "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| | news:SR******** ******@TK2MSFTN GXA02.phx.gbl.. .
| | > Thanks for Brock's suggestion.
| | >
| | > Hi Sck10,
| | >
| | > For Control class, we can access its container page instance through
the
| | > "Page" property. Also, if the control is dynamically created and
added
| on
| | > page, please make sure that before we access that Control.Page
propety,
| | the
| | > control has been added into the Page's control structure , otherwise,
| the
| | > "Page" property remains Nothing....
| | >
| | > Thanks,
| | >
| | > Steven Cheng
| | > Microsoft Online Support
| | >
| | > Get Secure! www.microsoft.com/security
| | > (This posting is provided "AS IS", with no warranties, and confers no
| | > rights.)
| | > --------------------
| |
| | > |
| | > | You need to do:
| | > |
| | > | Me.Page.ClientS cript.RegisterC lienbtScriptBlo ck(...)
| | > |
| | > | -Brock
| | > | DevelopMentor
| | > | http://staff.develop.com/ballen
| |
| |
| |
|
|

Nov 19 '05 #6
Thanks Steve,

I am still having difficulties getting the sub procedure to work once moved
to the "App_code" folder. When I call the class using "Call
class_General.S etFocusControl( Me.txtSearch)", I don't get an error, but it
doesn't go to the control.

Previously you said,
| Also, as I've mentioned in the former message, the "FocusContr ol" must
| already been added into a certain page's control structure before we
access its "Page" property, otherwise, that property remains Nothing.
I was wondering if this is what is happening and how can I test for this?
Thanks again for any insight.

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'Set Focus
Call class_General.S etFocusControl( Me.txtSearch)
' this works: Call SetFocusControl (Me.txtSearch)
End Sub
This works
---------------------
Public Shared Sub SetFocusControl (ByVal FocusControl As Control)

'class_General. SetFocusControl (Me.txtTraveler HRID)

Dim Script As New System.Text.Str ingBuilder
Dim ClientID As String = FocusControl.Cl ientID
With Script
.Append("<scrip t language='javas cript'>")
.Append("docume nt.getElementBy Id('")
.Append(ClientI D)
.Append("').foc us();")
.Append("</script>")
End With

FocusControl.Pa ge.ClientScript .RegisterClient ScriptBlock(Get Type(String),
"SetFocusOnCont rol", Script.ToString ())

End Sub
"App_Code" folder
-----------------
Imports Microsoft.Visua lBasic

Public Class class_General
Public Shared Sub SetFocusControl (ByVal FocusControl As Control)

'class_General. SetFocusControl (Me.txtTraveler HRID)

Dim Script As New System.Text.Str ingBuilder
Dim ClientID As String = FocusControl.Cl ientID
With Script
.Append("<scrip t language='javas cript'>")
.Append("docume nt.getElementBy Id('")
.Append(ClientI D)
.Append("').foc us();")
.Append("</script>")
End With

FocusControl.Pa ge.ClientScript .RegisterClient ScriptBlock(Get Type(String),
"SetFocusOnCont rol", Script.ToString ())

End Sub

Thanks again,

"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:xt******** ******@TK2MSFTN GXA02.phx.gbl.. . Hi Sck10,

Does the suggestions in my further response helps you? If there're anything else we can help, please feel free to post here.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 32396961
| References: <eJ************ **@TK2MSFTNGP09 .phx.gbl>
<b8************ **************@ msnews.microsof t.com>
<SR************ **@TK2MSFTNGXA0 2.phx.gbl>
<OB************ *@TK2MSFTNGP15. phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online. microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Fri, 11 Nov 2005 01:44:44 GMT
| Subject: Re: asp.net 2: Re-use code with
ClientScript.Re gisterStartupSc ript
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| Message-ID: <m4************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 108
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3572 42
| NNTP-Posting-Host: tomcatimport2.p hx.gbl 10.201.218.182
|
| Thanks for your response Sck10,
|
| What's the class of the "SetFocusContro l" method, from your code snippet
,
| the "SetFocusContro l" method is a static function so that it can not
access
| its container class's "Me" property. In addition, only class derived
from
| System.Web.UI.C ontrol has the "Page" propety... Is this class only a
| helper component class? If so, you need to use the passed in "Control"
| parameter 's "Page" property to register the script, e.g:
|
| =============== ==========
| Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
| Dim Script As New System.Text.Str ingBuilder
| Dim ClientID As String = FocusControl.Cl ientID
| With Script
| .Append("<scrip t language='javas cript'>")
| .Append("docume nt.getElementBy Id('")
| .Append(ClientI D)
| .Append("').foc us();")
| .Append("</script>")
| End With
|
|
| FocusControl.Pa ge.ClientScript .RegisterClienb tScriptBlock(Ge tType(String), | "SetFocusOnCont rol", Script.ToString ())
| ............... ............... .....
|
|
| =============== ======
|
| Also, as I've mentioend in the former message, the "FocusContr ol" must
| already been added into a certain page's control structure before we
access
| its "Page" property, otherwise, that property remains Nothing.
|
| Hope helps. Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
| --------------------
| | From: "sck10" <sc***@online.n ospam>
| | References: <eJ************ **@TK2MSFTNGP09 .phx.gbl>
| <b8************ **************@ msnews.microsof t.com>
| <SR************ **@TK2MSFTNGXA0 2.phx.gbl>
| | Subject: Re: asp.net 2: Re-use code with
| ClientScript.Re gisterStartupSc ript
| | Date: Thu, 10 Nov 2005 16:28:19 -0600
| | Lines: 62
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| | Message-ID: <OB************ *@TK2MSFTNGP15. phx.gbl>
| | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: 189.202.185.135 .in-addr.arpa 135.185.202.189
| | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:3572 02
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | Thanks Steve,
| |
| | I'm still having problems. I get the following error when trying to use | | "Me.Page". Also, I am only using "Imports Microsoft.Visua lBasic".
| |
| | error: 'Me' is valid only within an instance method.
| |
| | ---------------------------------
| | Imports Microsoft.Visua lBasic
| |
| | Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
| | Dim Script As New System.Text.Str ingBuilder
| | Dim ClientID As String = FocusControl.Cl ientID
| | With Script
| | .Append("<scrip t language='javas cript'>")
| | .Append("docume nt.getElementBy Id('")
| | .Append(ClientI D)
| | .Append("').foc us();")
| | .Append("</script>")
| | End With
| | 'Me.Page.Client Script.Register ClienbtScriptBl ock(GetType(Str ing),
| | "SetFocusOnCont rol", Script.ToString ())
| | 'Me.Page.Client Script.Register StartupScript(G etType(String),
| | "SetFocusOnCont rol", Script.ToString ())
| |
| |
| | End Sub
| |
| |
| | "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| | news:SR******** ******@TK2MSFTN GXA02.phx.gbl.. .
| | > Thanks for Brock's suggestion.
| | >
| | > Hi Sck10,
| | >
| | > For Control class, we can access its container page instance through
the
| | > "Page" property. Also, if the control is dynamically created and
added
| on
| | > page, please make sure that before we access that Control.Page
propety,
| | the
| | > control has been added into the Page's control structure , otherwise, | the
| | > "Page" property remains Nothing....
| | >
| | > Thanks,
| | >
| | > Steven Cheng
| | > Microsoft Online Support
| | >
| | > Get Secure! www.microsoft.com/security
| | > (This posting is provided "AS IS", with no warranties, and confers no | | > rights.)
| | > --------------------
| |
| | > |
| | > | You need to do:
| | > |
| | > | Me.Page.ClientS cript.RegisterC lienbtScriptBlo ck(...)
| | > |
| | > | -Brock
| | > | DevelopMentor
| | > | http://staff.develop.com/ballen
| |
| |
| |
|
|

Nov 20 '05 #7
Thanks for your followup Sck10,

In your case, I think we can check the following things:
1. Make sure when you use the Page.SetFocus function, the passed in
Control Parameter instance's ClientID has be the actual value which will be
rendered out as its "id" in client side html element(you can print out this
and view the rendered html to compare it...)

2. Check the rendered javascript code in the rendered html in clientside
browser to see whether the clientside code is registered correctly...

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "sck10" <sc***@online.n ospam>
| References: <eJ************ **@TK2MSFTNGP09 .phx.gbl>
<b8************ **************@ msnews.microsof t.com>
<SR************ **@TK2MSFTNGXA0 2.phx.gbl>
<OB************ *@TK2MSFTNGP15. phx.gbl>
<m4************ **@TK2MSFTNGXA0 2.phx.gbl>
<xt************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: Re: asp.net 2: Re-use code with
ClientScript.Re gisterStartupSc ript
| Date: Wed, 16 Nov 2005 17:37:20 -0600
| Lines: 256
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <ON************ *@TK2MSFTNGP11. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: 189.202.185.135 .in-addr.arpa 135.185.202.189
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP11.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3587 81
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Thanks Steve,
|
| I am still having difficulties getting the sub procedure to work once
moved
| to the "App_code" folder. When I call the class using "Call
| class_General.S etFocusControl( Me.txtSearch)", I don't get an error, but it
| doesn't go to the control.
|
| Previously you said,
| > | Also, as I've mentioned in the former message, the "FocusContr ol" must
| > | already been added into a certain page's control structure before we
| > access its "Page" property, otherwise, that property remains Nothing.
|
| I was wondering if this is what is happening and how can I test for this?
| Thanks again for any insight.
|
| Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
| 'Set Focus
| Call class_General.S etFocusControl( Me.txtSearch)
| ' this works: Call SetFocusControl (Me.txtSearch)
| End Sub
|
|
| This works
| ---------------------
| Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
|
| 'class_General. SetFocusControl (Me.txtTraveler HRID)
|
| Dim Script As New System.Text.Str ingBuilder
| Dim ClientID As String = FocusControl.Cl ientID
| With Script
| .Append("<scrip t language='javas cript'>")
| .Append("docume nt.getElementBy Id('")
| .Append(ClientI D)
| .Append("').foc us();")
| .Append("</script>")
| End With
|
|
FocusControl.Pa ge.ClientScript .RegisterClient ScriptBlock(Get Type(String),
| "SetFocusOnCont rol", Script.ToString ())
|
| End Sub
|
|
| "App_Code" folder
| -----------------
| Imports Microsoft.Visua lBasic
|
| Public Class class_General
| Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
|
| 'class_General. SetFocusControl (Me.txtTraveler HRID)
|
| Dim Script As New System.Text.Str ingBuilder
| Dim ClientID As String = FocusControl.Cl ientID
| With Script
| .Append("<scrip t language='javas cript'>")
| .Append("docume nt.getElementBy Id('")
| .Append(ClientI D)
| .Append("').foc us();")
| .Append("</script>")
| End With
|
|
FocusControl.Pa ge.ClientScript .RegisterClient ScriptBlock(Get Type(String),
| "SetFocusOnCont rol", Script.ToString ())
|
| End Sub
|
| Thanks again,
|
|
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:xt******** ******@TK2MSFTN GXA02.phx.gbl.. .
| > Hi Sck10,
| >
| > Does the suggestions in my further response helps you? If there're
| anything
| > else we can help, please feel free to post here.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
| > | X-Tomcat-ID: 32396961
| > | References: <eJ************ **@TK2MSFTNGP09 .phx.gbl>
| > <b8************ **************@ msnews.microsof t.com>
| > <SR************ **@TK2MSFTNGXA0 2.phx.gbl>
| > <OB************ *@TK2MSFTNGP15. phx.gbl>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain
| > | Content-Transfer-Encoding: 7bit
| > | From: st*****@online. microsoft.com (Steven Cheng[MSFT])
| > | Organization: Microsoft
| > | Date: Fri, 11 Nov 2005 01:44:44 GMT
| > | Subject: Re: asp.net 2: Re-use code with
| > ClientScript.Re gisterStartupSc ript
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > | Message-ID: <m4************ **@TK2MSFTNGXA0 2.phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | Lines: 108
| > | Path: TK2MSFTNGXA02.p hx.gbl
| > | Xref: TK2MSFTNGXA02.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:3572 42
| > | NNTP-Posting-Host: tomcatimport2.p hx.gbl 10.201.218.182
| > |
| > | Thanks for your response Sck10,
| > |
| > | What's the class of the "SetFocusContro l" method, from your code
snippet
| > ,
| > | the "SetFocusContro l" method is a static function so that it can not
| > access
| > | its container class's "Me" property. In addition, only class derived
| > from
| > | System.Web.UI.C ontrol has the "Page" propety... Is this class only
a
| > | helper component class? If so, you need to use the passed in
"Control"
| > | parameter 's "Page" property to register the script, e.g:
| > |
| > | =============== ==========
| > | Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
| > | Dim Script As New System.Text.Str ingBuilder
| > | Dim ClientID As String = FocusControl.Cl ientID
| > | With Script
| > | .Append("<scrip t language='javas cript'>")
| > | .Append("docume nt.getElementBy Id('")
| > | .Append(ClientI D)
| > | .Append("').foc us();")
| > | .Append("</script>")
| > | End With
| > |
| > |
| > |
| FocusControl.Pa ge.ClientScript .RegisterClienb tScriptBlock(Ge tType(String),
| > | "SetFocusOnCont rol", Script.ToString ())
| > | ............... ............... .....
| > |
| > |
| > | =============== ======
| > |
| > | Also, as I've mentioend in the former message, the "FocusContr ol" must
| > | already been added into a certain page's control structure before we
| > access
| > | its "Page" property, otherwise, that property remains Nothing.
| > |
| > | Hope helps. Thanks,
| > |
| > | Steven Cheng
| > | Microsoft Online Support
| > |
| > | Get Secure! www.microsoft.com/security
| > | (This posting is provided "AS IS", with no warranties, and confers no
| > | rights.)
| > |
| > |
| > | --------------------
| > | | From: "sck10" <sc***@online.n ospam>
| > | | References: <eJ************ **@TK2MSFTNGP09 .phx.gbl>
| > | <b8************ **************@ msnews.microsof t.com>
| > | <SR************ **@TK2MSFTNGXA0 2.phx.gbl>
| > | | Subject: Re: asp.net 2: Re-use code with
| > | ClientScript.Re gisterStartupSc ript
| > | | Date: Thu, 10 Nov 2005 16:28:19 -0600
| > | | Lines: 62
| > | | X-Priority: 3
| > | | X-MSMail-Priority: Normal
| > | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| > | | Message-ID: <OB************ *@TK2MSFTNGP15. phx.gbl>
| > | | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | | NNTP-Posting-Host: 189.202.185.135 .in-addr.arpa 135.185.202.189
| > | | Path:
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| > | | Xref: TK2MSFTNGXA02.p hx.gbl
| > | microsoft.publi c.dotnet.framew ork.aspnet:3572 02
| > | | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > | |
| > | | Thanks Steve,
| > | |
| > | | I'm still having problems. I get the following error when trying to
| use
| > | | "Me.Page". Also, I am only using "Imports Microsoft.Visua lBasic".
| > | |
| > | | error: 'Me' is valid only within an instance method.
| > | |
| > | | ---------------------------------
| > | | Imports Microsoft.Visua lBasic
| > | |
| > | | Public Shared Sub SetFocusControl (ByVal FocusControl As Control)
| > | | Dim Script As New System.Text.Str ingBuilder
| > | | Dim ClientID As String = FocusControl.Cl ientID
| > | | With Script
| > | | .Append("<scrip t language='javas cript'>")
| > | | .Append("docume nt.getElementBy Id('")
| > | | .Append(ClientI D)
| > | | .Append("').foc us();")
| > | | .Append("</script>")
| > | | End With
| > | |
'Me.Page.Client Script.Register ClienbtScriptBl ock(GetType(Str ing),
| > | | "SetFocusOnCont rol", Script.ToString ())
| > | | 'Me.Page.Client Script.Register StartupScript(G etType(String),
| > | | "SetFocusOnCont rol", Script.ToString ())
| > | |
| > | |
| > | | End Sub
| > | |
| > | |
| > | | "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| > | | news:SR******** ******@TK2MSFTN GXA02.phx.gbl.. .
| > | | > Thanks for Brock's suggestion.
| > | | >
| > | | > Hi Sck10,
| > | | >
| > | | > For Control class, we can access its container page instance
through
| > the
| > | | > "Page" property. Also, if the control is dynamically created and
| > added
| > | on
| > | | > page, please make sure that before we access that Control.Page
| > propety,
| > | | the
| > | | > control has been added into the Page's control structure ,
| otherwise,
| > | the
| > | | > "Page" property remains Nothing....
| > | | >
| > | | > Thanks,
| > | | >
| > | | > Steven Cheng
| > | | > Microsoft Online Support
| > | | >
| > | | > Get Secure! www.microsoft.com/security
| > | | > (This posting is provided "AS IS", with no warranties, and confers
| no
| > | | > rights.)
| > | | > --------------------
| > | |
| > | | > |
| > | | > | You need to do:
| > | | > |
| > | | > | Me.Page.ClientS cript.RegisterC lienbtScriptBlo ck(...)
| > | | > |
| > | | > | -Brock
| > | | > | DevelopMentor
| > | | > | http://staff.develop.com/ballen
| > | |
| > | |
| > | |
| > |
| > |
| >
|
|
|

Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6429
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
11
4010
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
8
4417
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an image, which will upload the record to a mySql db so users can then either view all profiles or query.. I.e. show all males in UK, all femails over 35 etc. Now, I'm not asking for How to do this but more what would be the best way? I've looked at...
2
106616
by: sky2070 | last post by:
i have two file with jobapp.html calling jobapp_action.php <HTML> <!-- jobapp.html --> <BODY> <H1>Phop's Bicycles Job Application</H1> <P>Are you looking for an exciting career in the world of cyclery? Look no further! </P> <FORM NAME='frmJobApp' METHOD=post ACTION="jobapp_action.php"> Please enter your name:
1
13657
by: Brian | last post by:
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
2
5313
by: JW | last post by:
I wanted have this as part of a flood control script: <? echo ("Flood control in place - please wait " . $floodinterval . " seconds between postings."); sleep(5); // go back two pages echo "<script>window.history.go(-2);</script>"; exit; ?>
6
3516
by: Chris Krasnichuk | last post by:
Hello every one, Does anyone know how to make php work on your computer? please reply I need help Chris
2
3344
by: Frans Schmidt | last post by:
I want to make a new database with several tables, so I did the following: <?php CREATE DATABASE bedrijf; CREATE TABLE werknemers (voornaam varchar(15), achternaam varchar(20), leeftijd tinyint(3), adres varchar(30), woonplaats varchar(20),
3
5387
by: Dell Sala | last post by:
I have recently enabled the PHP 4.2.1 that comes pre-installed on OS X. After making all the prescribed changes to the httpd.conf file php seems to work fine. I would like to make some changes to the php.ini file, but I can't find it. phpinfo() tells me that it is in /usr/lib but don't see the file there (or anywhere else). Even after creating my own php.ini file in /usr/lib my changes aren't acknowledged on the phpinfo() page. ...
20
11666
by: bb | last post by:
I'm not a Perl programmer nor a Linux adherent. What are the advantages of LAMP vs.the Java model for building data-driven websites? I do a fair amount of development using Tomcat/JSP/Servlets with Struts for clients. I see more and more ads for LAMP/PHP developers. What are the advantages and tradeoffs? All opinions welcomed....
0
9595
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.