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" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
| Subject: Re: asp.net 2: Re-use code with
ClientScript.RegisterStartupScript
| 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: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 189.202.185.135.in-addr.arpa 135.185.202.189
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:358781
| X-Tomcat-NG: microsoft.public.dotnet.framework.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.SetFocusControl(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 "FocusControl" 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.SetFocusControl(Me.txtSearch)
| ' this works: Call SetFocusControl(Me.txtSearch)
| End Sub
|
|
| This works
| ---------------------
| Public Shared Sub SetFocusControl(ByVal FocusControl As Control)
|
| 'class_General.SetFocusControl(Me.txtTravelerHRID)
|
| Dim Script As New System.Text.StringBuilder
| Dim ClientID As String = FocusControl.ClientID
| With Script
| .Append("<script language='javascript'>")
| .Append("document.getElementById('")
| .Append(ClientID)
| .Append("').focus();")
| .Append("</script>")
| End With
|
|
FocusControl.Page.ClientScript.RegisterClientScriptBlock(GetType(String),
| "SetFocusOnControl", Script.ToString())
|
| End Sub
|
|
| "App_Code" folder
| -----------------
| Imports Microsoft.VisualBasic
|
| Public Class class_General
| Public Shared Sub SetFocusControl(ByVal FocusControl As Control)
|
| 'class_General.SetFocusControl(Me.txtTravelerHRID)
|
| Dim Script As New System.Text.StringBuilder
| Dim ClientID As String = FocusControl.ClientID
| With Script
| .Append("<script language='javascript'>")
| .Append("document.getElementById('")
| .Append(ClientID)
| .Append("').focus();")
| .Append("</script>")
| End With
|
|
FocusControl.Page.ClientScript.RegisterClientScriptBlock(GetType(String),
| "SetFocusOnControl", Script.ToString())
|
| End Sub
|
| Thanks again,
|
|
|
| | > 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: <
[email protected]>
| > <
[email protected]>
| > <
[email protected]>
| > <
[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain
| > | Content-Transfer-Encoding: 7bit
| > | From: (e-mail address removed) (Steven Cheng[MSFT])
| > | Organization: Microsoft
| > | Date: Fri, 11 Nov 2005 01:44:44 GMT
| > | Subject: Re: asp.net 2: Re-use code with
| > ClientScript.RegisterStartupScript
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | Message-ID: <
[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | Lines: 108
| > | Path: TK2MSFTNGXA02.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:357242
| > | NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
| > |
| > | Thanks for your response Sck10,
| > |
| > | What's the class of the "SetFocusControl" method, from your code
snippet
| > ,
| > | the "SetFocusControl" 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.Control 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.StringBuilder
| > | Dim ClientID As String = FocusControl.ClientID
| > | With Script
| > | .Append("<script language='javascript'>")
| > | .Append("document.getElementById('")
| > | .Append(ClientID)
| > | .Append("').focus();")
| > | .Append("</script>")
| > | End With
| > |
| > |
| > |
| FocusControl.Page.ClientScript.RegisterClienbtScriptBlock(GetType(String),
| > | "SetFocusOnControl", Script.ToString())
| > | ...................................
| > |
| > |
| > | =====================
| > |
| > | Also, as I've mentioend in the former message, the "FocusControl" 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" <
[email protected]>
| > | | References: <
[email protected]>
| > | <
[email protected]>
| > | <
[email protected]>
| > | | Subject: Re: asp.net 2: Re-use code with
| > | ClientScript.RegisterStartupScript
| > | | 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: <
[email protected]>
| > | | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | | NNTP-Posting-Host: 189.202.185.135.in-addr.arpa 135.185.202.189
| > | | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| > | | Xref: TK2MSFTNGXA02.phx.gbl
| > | microsoft.public.dotnet.framework.aspnet:357202
| > | | X-Tomcat-NG: microsoft.public.dotnet.framework.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.VisualBasic".
| > | |
| > | | error: 'Me' is valid only within an instance method.
| > | |
| > | | ---------------------------------
| > | | Imports Microsoft.VisualBasic
| > | |
| > | | Public Shared Sub SetFocusControl(ByVal FocusControl As Control)
| > | | Dim Script As New System.Text.StringBuilder
| > | | Dim ClientID As String = FocusControl.ClientID
| > | | With Script
| > | | .Append("<script language='javascript'>")
| > | | .Append("document.getElementById('")
| > | | .Append(ClientID)
| > | | .Append("').focus();")
| > | | .Append("</script>")
| > | | End With
| > | |
'Me.Page.ClientScript.RegisterClienbtScriptBlock(GetType(String),
| > | | "SetFocusOnControl", Script.ToString())
| > | | 'Me.Page.ClientScript.RegisterStartupScript(GetType(String),
| > | | "SetFocusOnControl", Script.ToString())
| > | |
| > | |
| > | | End Sub
| > | |
| > | |
| > | | | > | | > 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.ClientScript.RegisterClienbtScriptBlock(...)
| > | | > |
| > | | > | -Brock
| > | | > | DevelopMentor
| > | | > |
http://staff.develop.com/ballen
| > | |
| > | |
| > | |
| > |
| > |
| >
|
|
|