Need OnClick ServerSide and ClientSide Event Handler

P

PK9

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;
}
 
P

PK9

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 said:
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 said:
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;
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top