Need OnClick ServerSide and ClientSide Event Handler

Discussion in 'ASP .Net Web Controls' started by PK9, Mar 6, 2005.

  1. PK9

    PK9 Guest

    I have a button at the top of my page that I have an onClick event handler
    for which makes some new controls (at the bottom of my page) visible. When
    the user clicks the button I make the new controls visible in the onclick
    server side event handler, but I do not know how to bring the focus to the
    bottom section of the page afterwards. So basically, when the user clicks
    the button, everything works correctly in the onclick server side event
    handler (all controls are made visible), however when the page is displayed,
    the user would have to scroll down to the bottom to find the new controls.

    I'm looking for a way to bring the attention to the bottom section of the
    page where the new controls are. Remember that I have to use the onclick
    server-side event handler to first make the controls visible.

    Here is my code for doing the server-side event handling, now I need to be
    able to do the client side (focusing on lstNewControl - a dropdown list):

    ASP.NET/ HTML CODE:
    <asp:Button ID="btnAddNewTitle" Runat="server" Text="Add New Title
    OnClick="btnAddNewTitle_Click" />
    .....Top of Page ....
    ..... contents of page ....
    ..... Bottom of Page ....
    <asp:DropDownList ID="lstNewTitle" Runat="server" visible=false />
    <asp:TextBox ID="txtNewControl" Runat="server" visible=false />
    CODE-BEHIND BUTTON CLICK EVENT HANDLER CODE:
    public void btnAddNewTitle_Click(object sender, System.EventArgs e)
    {
    lstNewTitle.visible = true;
    txtNewControl.visible = true;
    txtNewControl.enabled = false;
    }



    --
    PK9
     
    PK9, Mar 6, 2005
    #1
    1. Advertising

  2. PK9

    PK9 Guest

    Thanks Alvin, but my question is more centered on how to create this
    javascript as an event handler action on the client side, when I've already
    got a server side event handler. The control isn't even visible until after
    my button onClick server-side event handler runs. Therefore, I can't
    setFocus until the onClick event handler is complete. It's this part I'm
    unsure of, the way to set the focus "after" the onclick event handler of my
    button.

    "Alvin Bruney [ASP.NET MVP]" wrote:

    > txtNewControl.enabled = false
    > Response.Write("<script>txtNewControl.SetFocus()</script>")
    > should do the trick. Once the control has focus, the browser will make sure
    > that the control is in view. Another approach is to use a hidden textbox at
    > the same level of the control and setfocus to it. there are a couple more
    > approaches but these two should suffice.
    >
    > --
    > Regards,
    > Alvin Bruney
    >
    > [Shameless Author Plug]
    > The Microsoft Office Web Components Black Book with .NET
    > available at www.lulu.com/owc
    > ------------------------------------------------------------
    >
    > "PK9" <> wrote in message
    > news:...
    > >I have a button at the top of my page that I have an onClick event handler
    > > for which makes some new controls (at the bottom of my page) visible.
    > > When
    > > the user clicks the button I make the new controls visible in the onclick
    > > server side event handler, but I do not know how to bring the focus to the
    > > bottom section of the page afterwards. So basically, when the user clicks
    > > the button, everything works correctly in the onclick server side event
    > > handler (all controls are made visible), however when the page is
    > > displayed,
    > > the user would have to scroll down to the bottom to find the new controls.
    > >
    > > I'm looking for a way to bring the attention to the bottom section of the
    > > page where the new controls are. Remember that I have to use the onclick
    > > server-side event handler to first make the controls visible.
    > >
    > > Here is my code for doing the server-side event handling, now I need to be
    > > able to do the client side (focusing on lstNewControl - a dropdown list):
    > >
    > > ASP.NET/ HTML CODE:
    > > <asp:Button ID="btnAddNewTitle" Runat="server" Text="Add New Title
    > > OnClick="btnAddNewTitle_Click" />
    > > ....Top of Page ....
    > > .... contents of page ....
    > > .... Bottom of Page ....
    > > <asp:DropDownList ID="lstNewTitle" Runat="server" visible=false />
    > > <asp:TextBox ID="txtNewControl" Runat="server" visible=false />
    > > CODE-BEHIND BUTTON CLICK EVENT HANDLER CODE:
    > > public void btnAddNewTitle_Click(object sender, System.EventArgs e)
    > > {
    > > lstNewTitle.visible = true;
    > > txtNewControl.visible = true;
    > > txtNewControl.enabled = false;
    > > }
    > >
    > >
    > >
    > > --
    > > PK9

    >
    >
    >
     
    PK9, Mar 7, 2005
    #2
    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. Robin Day
    Replies:
    3
    Views:
    4,464
    Alessandro Zifiglio
    Jan 21, 2004
  2. Luis Ferrao
    Replies:
    2
    Views:
    564
    Luis Ferrao
    Feb 21, 2005
  3. csgraham74
    Replies:
    5
    Views:
    5,449
    csgraham74
    Jun 14, 2005
  4. Robin Day

    Checkboxlist Clientside rather than Serverside

    Robin Day, Jan 20, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    189
    Alessandro Zifiglio
    Jan 21, 2004
  5. Replies:
    0
    Views:
    167
Loading...

Share This Page