Re: Set Focus
From: Jerry Pisk (jerryiii_at_hotmail.com)
Date: 09/01/04
- Next message: Nick Malik: "Re: URGENT- how to install .net framework on sql cluster2k on win2003"
- Previous message: GirishKumar: "Re: Using VB.Net or C#, utilizing the clipboard object, how to cop"
- Next in thread: Rookie: "Re: Set Focus"
- Reply: Rookie: "Re: Set Focus"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 31 Aug 2004 22:41:35 -0700
No it doesn't. You're calling it from the server side handler, rendering the
script into the page at a place where the form is not parsed. I got a little
confused here, I thought you want to handle this on the client side, not
through a postback. You should put the script either into the client side
handler or render it after the form is closed. I don't like the whole
postback architecture in Asp.Net so I won't be able to help you much here.
But if you want to do this using HTML and client side scripts it's really
simple, all you need is to render something like this:
<select onchange="document.forms['myForm'].elemwnts['txtTest'].focus();">
<!-- Your options are here -->
</select>
<input type="text" name="txtTest" />
Jerry
"Rookie" <Rookie@discussions.microsoft.com> wrote in message
news:70BE692D-7F34-49A6-B80F-7B5AAE3541F6@microsoft.com...
> Hi Jerry,
>
> This is what I posted in my second message:
>
> Private Sub lstMyList_SelectedIndexChanged(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles lstMyList.SelectedIndexChanged
> <Here goes my listbox vb code where I used dataset and blah blah blah and
> then...>
> Dim stScript As String
> stScript = "<script language=""JavaScript"">"
> stScript +=
> "document.forms[""myForm""].elements[""txtTest""].focus();"
> stScript += "<"
> stScript += "/"
> stScript += "script>"
> If (Not IsClientScriptBlockRegistered("jsfocus")) Then
> RegisterClientScriptBlock("jsfocus", stScript)
> End If
>
> End Sub
>
> Doesn't it mean I am calling it from the listbox's event handler?
>
> Rookie
>
> "Jerry Pisk" wrote:
>
>> So you're saying you're calling it from your listbox's event handler?
>> That's
>> not what you posted. Either make that code the listbox's event handler
>> (onchange probably) or put it in a function and call it when ready. The
>> code
>> you posted does neither, it simply renders the script to be executed as
>> the
>> form is being loaded, before all the contents is processed - which is
>> going
>> to fail.
>>
>> It seems that you might want to do some research on how client scripts
>> work
>> and when they execute...
>>
>> Jerry
>>
>> "Rookie" <Rookie@discussions.microsoft.com> wrote in message
>> news:DA133FF8-CA79-4916-B40D-473819EEFB71@microsoft.com...
>> > Hi Jerry,
>> > I am doing some task with the listbox before I call the setfocus. If I
>> > put
>> > setfocus function after the form's closing tag, I need to set onclick
>> > for
>> > listbox to the function. This is OK if I dont do anything with the
>> > listbox
>> > except for setting focus to the textbox. However, I perform some data
>> > operations before I want to set focus to the textbox. How do I do that
>> > unless
>> > I render the script dynamically?
>> > Rookie
>> >
>> > "Jerry Pisk" wrote:
>> >
>> >> I found the problem - Page.RegisterClientScriptBlock causes the script
>> >> to
>> >> be
>> >> rendered just after the opening form tag. At that point the browser
>> >> doesn't
>> >> know about any elements inside the form. You need to render the script
>> >> after
>> >> your form's closing tag. Just put the script into the page, there's
>> >> really
>> >> no need to render it dynamically.
>> >>
>> >> Jerry
>>
>>
>>
- Next message: Nick Malik: "Re: URGENT- how to install .net framework on sql cluster2k on win2003"
- Previous message: GirishKumar: "Re: Using VB.Net or C#, utilizing the clipboard object, how to cop"
- Next in thread: Rookie: "Re: Set Focus"
- Reply: Rookie: "Re: Set Focus"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|