Giving Focus on PostBack

Discussion in 'ASP .Net' started by tshad, Feb 15, 2005.

  1. tshad

    tshad Guest

    I have a page where I give focus to the first textbox on my page:

    <body onLoad="document.forms[0].firstName.focus();">

    I also go and check the status of some data when I exit the 3rd textbox on
    my screen.

    The problem is that the screen jumps back to the first textbox because of
    the onLoad statement when the page is posted back. Is there an easy way to
    tell it to do the Onload only once and to go the next textbox on the repost?

    Thanks,

    Tom
     
    tshad, Feb 15, 2005
    #1
    1. Advertising

  2. tshad

    Andy G Guest

    I think this is what you want....

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    If Not IsPostBack Then

    <body onLoad="document.forms[0].firstName.focus();">

    End If

    End Sub



    "tshad" <> wrote in message
    news:...
    > I have a page where I give focus to the first textbox on my page:
    >
    > <body onLoad="document.forms[0].firstName.focus();">
    >
    > I also go and check the status of some data when I exit the 3rd textbox on
    > my screen.
    >
    > The problem is that the screen jumps back to the first textbox because of
    > the onLoad statement when the page is posted back. Is there an easy way

    to
    > tell it to do the Onload only once and to go the next textbox on the

    repost?
    >
    > Thanks,
    >
    > Tom
    >
    >
     
    Andy G, Feb 15, 2005
    #2
    1. Advertising

  3. tshad

    tshad Guest

    "Andy G" <> wrote in message
    news:...
    >I think this is what you want....
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    >
    > If Not IsPostBack Then
    >
    > <body onLoad="document.forms[0].firstName.focus();">
    >
    > End If
    >
    > End Sub
    >


    I tried that but got the error:

    Compiler Error Message: BC30636: '>' expected.

    My code is:

    Sub Page_Load(sender as Object, e as EventArgs)
    if not IsPostBack then
    <body onLoad="document.forms[0].firstName.focus();">
    end if
    end sub

    Tom
    >
    >
    > "tshad" <> wrote in message
    > news:...
    >> I have a page where I give focus to the first textbox on my page:
    >>
    >> <body onLoad="document.forms[0].firstName.focus();">
    >>
    >> I also go and check the status of some data when I exit the 3rd textbox
    >> on
    >> my screen.
    >>
    >> The problem is that the screen jumps back to the first textbox because of
    >> the onLoad statement when the page is posted back. Is there an easy way

    > to
    >> tell it to do the Onload only once and to go the next textbox on the

    > repost?
    >>
    >> Thanks,
    >>
    >> Tom
    >>
    >>

    >
    >
     
    tshad, Feb 15, 2005
    #3
  4. tshad

    Shawn Guest

    Hi.
    Add a Runat="server" and id="myBody" to the body tag in the aspx file. Then
    put this in your code behind:
    Protected WithEvents myBody As System.Web.UI.HtmlControls.HtmlGenericControl

    Now you can add the javascript in you page load method, like this:
    If Not IsPostBack Then
    myBody.Attributes.Add("onLoad",
    "document.forms[0].the_id_of_the_first_textbox.focus();")
    End If

    Shawn

    "tshad" <> wrote in message
    news:...
    > "Andy G" <> wrote in message
    > news:...
    > >I think this is what you want....
    > >
    > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > > System.EventArgs) Handles MyBase.Load
    > >
    > > If Not IsPostBack Then
    > >
    > > <body onLoad="document.forms[0].firstName.focus();">
    > >
    > > End If
    > >
    > > End Sub
    > >

    >
    > I tried that but got the error:
    >
    > Compiler Error Message: BC30636: '>' expected.
    >
    > My code is:
    >
    > Sub Page_Load(sender as Object, e as EventArgs)
    > if not IsPostBack then
    > <body onLoad="document.forms[0].firstName.focus();">
    > end if
    > end sub
    >
    > Tom
    > >
    > >
    > > "tshad" <> wrote in message
    > > news:...
    > >> I have a page where I give focus to the first textbox on my page:
    > >>
    > >> <body onLoad="document.forms[0].firstName.focus();">
    > >>
    > >> I also go and check the status of some data when I exit the 3rd textbox
    > >> on
    > >> my screen.
    > >>
    > >> The problem is that the screen jumps back to the first textbox because

    of
    > >> the onLoad statement when the page is posted back. Is there an easy

    way
    > > to
    > >> tell it to do the Onload only once and to go the next textbox on the

    > > repost?
    > >>
    > >> Thanks,
    > >>
    > >> Tom
    > >>
    > >>

    > >
    > >

    >
    >
     
    Shawn, Feb 15, 2005
    #4
  5. tshad

    tshad Guest

    "Shawn" <> wrote in message
    news:...
    > Hi.
    > Add a Runat="server" and id="myBody" to the body tag in the aspx file.
    > Then
    > put this in your code behind:
    > Protected WithEvents myBody As
    > System.Web.UI.HtmlControls.HtmlGenericControl
    >
    > Now you can add the javascript in you page load method, like this:
    > If Not IsPostBack Then
    > myBody.Attributes.Add("onLoad",
    > "document.forms[0].the_id_of_the_first_textbox.focus();")
    > End If


    I tried that and got the following error (even though there is a </body> at
    the bottom of the page):
    ********************************************************
    Parser Error Message: Unexpected end of file looking for </body> tag.

    Source Error:

    Line 433:</head>
    Line 434:<link href="staffing.css" rel="stylesheet" type="text/css">
    Line 435:<body id="myBody" runat="server">
    Line 436:<fts:header id=ctl1 runat="Server" />
    *******************************************************
    Do I need to do something else (need to body tags - I wouldn't think so).

    Tom
    >
    > Shawn
    >
    > "tshad" <> wrote in message
    > news:...
    >> "Andy G" <> wrote in message
    >> news:...
    >> >I think this is what you want....
    >> >
    >> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    >> > System.EventArgs) Handles MyBase.Load
    >> >
    >> > If Not IsPostBack Then
    >> >
    >> > <body onLoad="document.forms[0].firstName.focus();">
    >> >
    >> > End If
    >> >
    >> > End Sub
    >> >

    >>
    >> I tried that but got the error:
    >>
    >> Compiler Error Message: BC30636: '>' expected.
    >>
    >> My code is:
    >>
    >> Sub Page_Load(sender as Object, e as EventArgs)
    >> if not IsPostBack then
    >> <body onLoad="document.forms[0].firstName.focus();">
    >> end if
    >> end sub
    >>
    >> Tom
    >> >
    >> >
    >> > "tshad" <> wrote in message
    >> > news:...
    >> >> I have a page where I give focus to the first textbox on my page:
    >> >>
    >> >> <body onLoad="document.forms[0].firstName.focus();">
    >> >>
    >> >> I also go and check the status of some data when I exit the 3rd
    >> >> textbox
    >> >> on
    >> >> my screen.
    >> >>
    >> >> The problem is that the screen jumps back to the first textbox because

    > of
    >> >> the onLoad statement when the page is posted back. Is there an easy

    > way
    >> > to
    >> >> tell it to do the Onload only once and to go the next textbox on the
    >> > repost?
    >> >>
    >> >> Thanks,
    >> >>
    >> >> Tom
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
     
    tshad, Feb 16, 2005
    #5
  6. tshad

    tshad Guest

    "tshad" <> wrote in message
    news:...
    > "Shawn" <> wrote in message
    > news:...
    >> Hi.
    >> Add a Runat="server" and id="myBody" to the body tag in the aspx file.
    >> Then
    >> put this in your code behind:
    >> Protected WithEvents myBody As
    >> System.Web.UI.HtmlControls.HtmlGenericControl
    >>
    >> Now you can add the javascript in you page load method, like this:
    >> If Not IsPostBack Then
    >> myBody.Attributes.Add("onLoad",
    >> "document.forms[0].the_id_of_the_first_textbox.focus();")
    >> End If

    >
    > I tried that and got the following error (even though there is a </body>
    > at the bottom of the page):
    > ********************************************************
    > Parser Error Message: Unexpected end of file looking for </body> tag.
    >
    > Source Error:
    >
    > Line 433:</head>
    > Line 434:<link href="staffing.css" rel="stylesheet" type="text/css">
    > Line 435:<body id="myBody" runat="server">
    > Line 436:<fts:header id=ctl1 runat="Server" />
    > *******************************************************
    > Do I need to do something else (need to body tags - I wouldn't think so).
    >


    I found out what was causing this error, although it makes user controls a
    bit of a problem

    At the bottom of my page I have:

    <fts:footer id=ctl2 runat="Server" />

    This has the following code in it:

    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </body>
    </html>

    If I take out the control and just put this code it by hand, I don't get the
    error.

    Also, This doesn't seem to work. Even though I am adding the the "onload"
    to the body attribute, it is still there when the page is re-posted, so it
    always goes back to the first textbox.

    Tom
     
    tshad, Feb 16, 2005
    #6
  7. tshad

    tshad Guest

    I was just thinking:

    If you do:

    myBody.Attributes.Add("onLoad",
    "document.forms[0].the_id_of_the_first_textbox.focus();")

    to add the attribute during Page_Load, is there a corresponding:

    myBody.Attributes.remove (or something like that take it out).

    This then allow me to take if off during the repost, which is what is
    causing my problem.

    Thanks,

    Tom



    "tshad" <> wrote in message
    news:%...
    >
    > "tshad" <> wrote in message
    > news:...
    >> "Shawn" <> wrote in message
    >> news:...
    >>> Hi.
    >>> Add a Runat="server" and id="myBody" to the body tag in the aspx file.
    >>> Then
    >>> put this in your code behind:
    >>> Protected WithEvents myBody As
    >>> System.Web.UI.HtmlControls.HtmlGenericControl
    >>>
    >>> Now you can add the javascript in you page load method, like this:
    >>> If Not IsPostBack Then
    >>> myBody.Attributes.Add("onLoad",
    >>> "document.forms[0].the_id_of_the_first_textbox.focus();")
    >>> End If

    >>
    >> I tried that and got the following error (even though there is a </body>
    >> at the bottom of the page):
    >> ********************************************************
    >> Parser Error Message: Unexpected end of file looking for </body> tag.
    >>
    >> Source Error:
    >>
    >> Line 433:</head>
    >> Line 434:<link href="staffing.css" rel="stylesheet" type="text/css">
    >> Line 435:<body id="myBody" runat="server">
    >> Line 436:<fts:header id=ctl1 runat="Server" />
    >> *******************************************************
    >> Do I need to do something else (need to body tags - I wouldn't think so).
    >>

    >
    > I found out what was causing this error, although it makes user controls a
    > bit of a problem
    >
    > At the bottom of my page I have:
    >
    > <fts:footer id=ctl2 runat="Server" />
    >
    > This has the following code in it:
    >
    > </td>
    > </tr>
    > </table>
    > </td>
    > </tr>
    > </table>
    > </body>
    > </html>
    >
    > If I take out the control and just put this code it by hand, I don't get
    > the error.
    >
    > Also, This doesn't seem to work. Even though I am adding the the
    > "onload" to the body attribute, it is still there when the page is
    > re-posted, so it always goes back to the first textbox.
    >
    > Tom
    >
     
    tshad, Feb 17, 2005
    #7
  8. tshad

    Shawn Guest

    Well, you can just clear it, like this: myBody.Attributes.Item("onLoad") =
    ""
    Shawn

    "tshad" <> wrote in message
    news:...
    > I was just thinking:
    >
    > If you do:
    >
    > myBody.Attributes.Add("onLoad",
    > "document.forms[0].the_id_of_the_first_textbox.focus();")
    >
    > to add the attribute during Page_Load, is there a corresponding:
    >
    > myBody.Attributes.remove (or something like that take it out).
    >
    > This then allow me to take if off during the repost, which is what is
    > causing my problem.
    >
    > Thanks,
    >
    > Tom
    >
    >
    >
    > "tshad" <> wrote in message
    > news:%...
    > >
    > > "tshad" <> wrote in message
    > > news:...
    > >> "Shawn" <> wrote in message
    > >> news:...
    > >>> Hi.
    > >>> Add a Runat="server" and id="myBody" to the body tag in the aspx file.
    > >>> Then
    > >>> put this in your code behind:
    > >>> Protected WithEvents myBody As
    > >>> System.Web.UI.HtmlControls.HtmlGenericControl
    > >>>
    > >>> Now you can add the javascript in you page load method, like this:
    > >>> If Not IsPostBack Then
    > >>> myBody.Attributes.Add("onLoad",
    > >>> "document.forms[0].the_id_of_the_first_textbox.focus();")
    > >>> End If
    > >>
    > >> I tried that and got the following error (even though there is a

    </body>
    > >> at the bottom of the page):
    > >> ********************************************************
    > >> Parser Error Message: Unexpected end of file looking for </body> tag.
    > >>
    > >> Source Error:
    > >>
    > >> Line 433:</head>
    > >> Line 434:<link href="staffing.css" rel="stylesheet" type="text/css">
    > >> Line 435:<body id="myBody" runat="server">
    > >> Line 436:<fts:header id=ctl1 runat="Server" />
    > >> *******************************************************
    > >> Do I need to do something else (need to body tags - I wouldn't think

    so).
    > >>

    > >
    > > I found out what was causing this error, although it makes user controls

    a
    > > bit of a problem
    > >
    > > At the bottom of my page I have:
    > >
    > > <fts:footer id=ctl2 runat="Server" />
    > >
    > > This has the following code in it:
    > >
    > > </td>
    > > </tr>
    > > </table>
    > > </td>
    > > </tr>
    > > </table>
    > > </body>
    > > </html>
    > >
    > > If I take out the control and just put this code it by hand, I don't get
    > > the error.
    > >
    > > Also, This doesn't seem to work. Even though I am adding the the
    > > "onload" to the body attribute, it is still there when the page is
    > > re-posted, so it always goes back to the first textbox.
    > >
    > > Tom
    > >

    >
    >
     
    Shawn, Feb 18, 2005
    #8
  9. tshad

    tshad Guest

    "Shawn" <> wrote in message
    news:upw8G$...
    > Well, you can just clear it, like this: myBody.Attributes.Item("onLoad") =
    > ""


    That was what I was looking for, but it didn't do what I wanted.

    When I post back, it goes to the first link at the top of the page.

    What I am doing is this:

    I have 10 textboxes. When I enter the page the first time, I give focus to
    the first text box. After the 3 textbox, I go check to see if what was
    entered was valid and if valid, I fill the rest of the text boxes. I then
    want it to go to the next text box. It goes to the first textbox when it
    comes back (the old way) and to the top of the page (the second way when I
    set onload to "").

    It makes sense as to why it does this. But is there a way to know where it
    was on exit (which would be the third box) and then go to the 4th text box
    on reentry?

    Thanks,

    Tom
    > Shawn
    >
    > "tshad" <> wrote in message
    > news:...
    >> I was just thinking:
    >>
    >> If you do:
    >>
    >> myBody.Attributes.Add("onLoad",
    >> "document.forms[0].the_id_of_the_first_textbox.focus();")
    >>
    >> to add the attribute during Page_Load, is there a corresponding:
    >>
    >> myBody.Attributes.remove (or something like that take it out).
    >>
    >> This then allow me to take if off during the repost, which is what is
    >> causing my problem.
    >>
    >> Thanks,
    >>
    >> Tom
    >>
    >>
    >>
    >> "tshad" <> wrote in message
    >> news:%...
    >> >
    >> > "tshad" <> wrote in message
    >> > news:...
    >> >> "Shawn" <> wrote in message
    >> >> news:...
    >> >>> Hi.
    >> >>> Add a Runat="server" and id="myBody" to the body tag in the aspx
    >> >>> file.
    >> >>> Then
    >> >>> put this in your code behind:
    >> >>> Protected WithEvents myBody As
    >> >>> System.Web.UI.HtmlControls.HtmlGenericControl
    >> >>>
    >> >>> Now you can add the javascript in you page load method, like this:
    >> >>> If Not IsPostBack Then
    >> >>> myBody.Attributes.Add("onLoad",
    >> >>> "document.forms[0].the_id_of_the_first_textbox.focus();")
    >> >>> End If
    >> >>
    >> >> I tried that and got the following error (even though there is a

    > </body>
    >> >> at the bottom of the page):
    >> >> ********************************************************
    >> >> Parser Error Message: Unexpected end of file looking for </body> tag.
    >> >>
    >> >> Source Error:
    >> >>
    >> >> Line 433:</head>
    >> >> Line 434:<link href="staffing.css" rel="stylesheet" type="text/css">
    >> >> Line 435:<body id="myBody" runat="server">
    >> >> Line 436:<fts:header id=ctl1 runat="Server" />
    >> >> *******************************************************
    >> >> Do I need to do something else (need to body tags - I wouldn't think

    > so).
    >> >>
    >> >
    >> > I found out what was causing this error, although it makes user
    >> > controls

    > a
    >> > bit of a problem
    >> >
    >> > At the bottom of my page I have:
    >> >
    >> > <fts:footer id=ctl2 runat="Server" />
    >> >
    >> > This has the following code in it:
    >> >
    >> > </td>
    >> > </tr>
    >> > </table>
    >> > </td>
    >> > </tr>
    >> > </table>
    >> > </body>
    >> > </html>
    >> >
    >> > If I take out the control and just put this code it by hand, I don't
    >> > get
    >> > the error.
    >> >
    >> > Also, This doesn't seem to work. Even though I am adding the the
    >> > "onload" to the body attribute, it is still there when the page is
    >> > re-posted, so it always goes back to the first textbox.
    >> >
    >> > Tom
    >> >

    >>
    >>

    >
    >
     
    tshad, Feb 18, 2005
    #9
  10. tshad

    tshad Guest

    "tshad" <> wrote in message
    news:...
    > "Shawn" <> wrote in message
    > news:upw8G$...
    >> Well, you can just clear it, like this: myBody.Attributes.Item("onLoad")
    >> =
    >> ""

    >
    > That was what I was looking for, but it didn't do what I wanted.
    >
    > When I post back, it goes to the first link at the top of the page.
    >
    > What I am doing is this:
    >
    > I have 10 textboxes. When I enter the page the first time, I give focus
    > to the first text box. After the 3 textbox, I go check to see if what was
    > entered was valid and if valid, I fill the rest of the text boxes. I then
    > want it to go to the next text box. It goes to the first textbox when it
    > comes back (the old way) and to the top of the page (the second way when I
    > set onload to "").
    >
    > It makes sense as to why it does this. But is there a way to know where
    > it was on exit (which would be the third box) and then go to the 4th text
    > box on reentry?


    I figured it out.

    I just needed to add:

    myBody.Attributes.Item("onLoad") =
    "document.forms[0].ticklerPhrase.focus()"

    to my IsPostBack section.

    Thanks,

    Tom
    >
    > Thanks,
    >
    > Tom
    >> Shawn
    >>
    >> "tshad" <> wrote in message
    >> news:...
    >>> I was just thinking:
    >>>
    >>> If you do:
    >>>
    >>> myBody.Attributes.Add("onLoad",
    >>> "document.forms[0].the_id_of_the_first_textbox.focus();")
    >>>
    >>> to add the attribute during Page_Load, is there a corresponding:
    >>>
    >>> myBody.Attributes.remove (or something like that take it out).
    >>>
    >>> This then allow me to take if off during the repost, which is what is
    >>> causing my problem.
    >>>
    >>> Thanks,
    >>>
    >>> Tom
    >>>
    >>>
    >>>
    >>> "tshad" <> wrote in message
    >>> news:%...
    >>> >
    >>> > "tshad" <> wrote in message
    >>> > news:...
    >>> >> "Shawn" <> wrote in message
    >>> >> news:...
    >>> >>> Hi.
    >>> >>> Add a Runat="server" and id="myBody" to the body tag in the aspx
    >>> >>> file.
    >>> >>> Then
    >>> >>> put this in your code behind:
    >>> >>> Protected WithEvents myBody As
    >>> >>> System.Web.UI.HtmlControls.HtmlGenericControl
    >>> >>>
    >>> >>> Now you can add the javascript in you page load method, like this:
    >>> >>> If Not IsPostBack Then
    >>> >>> myBody.Attributes.Add("onLoad",
    >>> >>> "document.forms[0].the_id_of_the_first_textbox.focus();")
    >>> >>> End If
    >>> >>
    >>> >> I tried that and got the following error (even though there is a

    >> </body>
    >>> >> at the bottom of the page):
    >>> >> ********************************************************
    >>> >> Parser Error Message: Unexpected end of file looking for </body> tag.
    >>> >>
    >>> >> Source Error:
    >>> >>
    >>> >> Line 433:</head>
    >>> >> Line 434:<link href="staffing.css" rel="stylesheet" type="text/css">
    >>> >> Line 435:<body id="myBody" runat="server">
    >>> >> Line 436:<fts:header id=ctl1 runat="Server" />
    >>> >> *******************************************************
    >>> >> Do I need to do something else (need to body tags - I wouldn't think

    >> so).
    >>> >>
    >>> >
    >>> > I found out what was causing this error, although it makes user
    >>> > controls

    >> a
    >>> > bit of a problem
    >>> >
    >>> > At the bottom of my page I have:
    >>> >
    >>> > <fts:footer id=ctl2 runat="Server" />
    >>> >
    >>> > This has the following code in it:
    >>> >
    >>> > </td>
    >>> > </tr>
    >>> > </table>
    >>> > </td>
    >>> > </tr>
    >>> > </table>
    >>> > </body>
    >>> > </html>
    >>> >
    >>> > If I take out the control and just put this code it by hand, I don't
    >>> > get
    >>> > the error.
    >>> >
    >>> > Also, This doesn't seem to work. Even though I am adding the the
    >>> > "onload" to the body attribute, it is still there when the page is
    >>> > re-posted, so it always goes back to the first textbox.
    >>> >
    >>> > Tom
    >>> >
    >>>
    >>>

    >>
    >>

    >
    >
     
    tshad, Feb 18, 2005
    #10
  11. Scott Guthrie demonstrates a great reusable way to get this functionality.

    Look at the ASP.NET BlackBelt WebForms talk in the TechEd 2003
    Presentations section.
    http://www.scottgu.com/

    Joshua Flanagan
    http://flimflan.com/blog



    tshad wrote:
    > "tshad" <> wrote in message
    > news:...
    >
    >>"Shawn" <> wrote in message
    >>news:upw8G$...
    >>
    >>>Well, you can just clear it, like this: myBody.Attributes.Item("onLoad")
    >>>=
    >>>""

    >>
    >>That was what I was looking for, but it didn't do what I wanted.
    >>
    >>When I post back, it goes to the first link at the top of the page.
    >>
    >>What I am doing is this:
    >>
    >>I have 10 textboxes. When I enter the page the first time, I give focus way
    >>entered was valid and if valid, I fill the rest of the text boxes. I then
    >>want it to go to the next text box. It goes to the first textbox when it
    >>comes back (the old way) and to the top of the page (the second way when I
    >>set onload to "").
    >>
    >>It makes sense as to why it does this. But is there a way to know where
    >>it was on exit (which would be the third box) and then go to the 4th text
    >>box on reentry?

    >
    >
    > I figured it out.
    >
    > I just needed to add:
    >
    > myBody.Attributes.Item("onLoad") =
    > "document.forms[0].ticklerPhrase.focus()"
    >
    > to my IsPostBack section.
    >
    > Thanks,
    >
    > Tom
    >
    >>Thanks,
    >>
    >>Tom
    >>
    >>>Shawn
    >>>
    >>>"tshad" <> wrote in message
    >>>news:...
    >>>
    >>>>I was just thinking:
    >>>>
    >>>>If you do:
    >>>>
    >>>>myBody.Attributes.Add("onLoad",
    >>>>"document.forms[0].the_id_of_the_first_textbox.focus();")
    >>>>
    >>>>to add the attribute during Page_Load, is there a corresponding:
    >>>>
    >>>>myBody.Attributes.remove (or something like that take it out).
    >>>>
    >>>>This then allow me to take if off during the repost, which is what is
    >>>>causing my problem.
    >>>>
    >>>>Thanks,
    >>>>
    >>>>Tom
    >>>>
    >>>>
    >>>>
    >>>>"tshad" <> wrote in message
    >>>>news:%...
    >>>>
    >>>>>"tshad" <> wrote in message
    >>>>>news:...
    >>>>>
    >>>>>>"Shawn" <> wrote in message
    >>>>>>news:...
    >>>>>>
    >>>>>>>Hi.
    >>>>>>>Add a Runat="server" and id="myBody" to the body tag in the aspx
    >>>>>>>file.
    >>>>>>>Then
    >>>>>>>put this in your code behind:
    >>>>>>>Protected WithEvents myBody As
    >>>>>>>System.Web.UI.HtmlControls.HtmlGenericControl
    >>>>>>>
    >>>>>>>Now you can add the javascript in you page load method, like this:
    >>>>>>>If Not IsPostBack Then
    >>>>>>> myBody.Attributes.Add("onLoad",
    >>>>>>>"document.forms[0].the_id_of_the_first_textbox.focus();")
    >>>>>>>End If
    >>>>>>
    >>>>>>I tried that and got the following error (even though there is a
    >>>
    >>></body>
    >>>
    >>>>>>at the bottom of the page):
    >>>>>>********************************************************
    >>>>>>Parser Error Message: Unexpected end of file looking for </body> tag.
    >>>>>>
    >>>>>>Source Error:
    >>>>>>
    >>>>>>Line 433:</head>
    >>>>>>Line 434:<link href="staffing.css" rel="stylesheet" type="text/css">
    >>>>>>Line 435:<body id="myBody" runat="server">
    >>>>>>Line 436:<fts:header id=ctl1 runat="Server" />
    >>>>>>*******************************************************
    >>>>>>Do I need to do something else (need to body tags - I wouldn't think
    >>>
    >>>so).
    >>>
    >>>>>I found out what was causing this error, although it makes user
    >>>>>controls
    >>>
    >>>a
    >>>
    >>>>>bit of a problem
    >>>>>
    >>>>>At the bottom of my page I have:
    >>>>>
    >>>>><fts:footer id=ctl2 runat="Server" />
    >>>>>
    >>>>>This has the following code in it:
    >>>>>
    >>>>> </td>
    >>>>> </tr>
    >>>>> </table>
    >>>>> </td>
    >>>>></tr>
    >>>>></table>
    >>>>></body>
    >>>>></html>
    >>>>>
    >>>>>If I take out the control and just put this code it by hand, I don't
    >>>>>get
    >>>>>the error.
    >>>>>
    >>>>>Also, This doesn't seem to work. Even though I am adding the the
    >>>>>"onload" to the body attribute, it is still there when the page is
    >>>>>re-posted, so it always goes back to the first textbox.
    >>>>>
    >>>>>Tom
    >>>>>
    >>>>
    >>>>
    >>>

    >>

    >
    >
     
    Joshua Flanagan, Feb 28, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Steiner
    Replies:
    0
    Views:
    463
    Scott Steiner
    May 9, 2005
  2. new Karoo

    giving form input bos focus

    new Karoo, Jul 24, 2003, in forum: HTML
    Replies:
    4
    Views:
    600
    Jukka K. Korpela
    Jul 26, 2003
  3. Mike
    Replies:
    1
    Views:
    15,725
    marss
    May 30, 2006
  4. sixteenmillion

    The giving that keeps on giving

    sixteenmillion, Nov 19, 2007, in forum: C Programming
    Replies:
    0
    Views:
    444
    sixteenmillion
    Nov 19, 2007
  5. Roger
    Replies:
    3
    Views:
    345
Loading...

Share This Page