Showing posts with label focus. Show all posts
Showing posts with label focus. Show all posts

Wednesday, March 28, 2012

How do I set focus on CascadingDropDown?

I'm trying to set focus on a Dropdownlist that's being populated by the nice CascadingDropDown tool. But I can't. Everything else works great, The forms retreive, insert, update without page postbacks via updatepanel. The CascadingDropDown tools work well with the dropdownlists and it all populates dependent on each other and without page postbacks. BUT I can't seem to set the focus to the dropdownlist that's being populated by the CascadingDropDown tool..

I've got the scriptmanager on the masterpage and the Dropdownlist I want to set focus upon is in a formview. I want it to set focus on the control when the form is changed to a insert or edit mode.

So my code behind is like this:

protectedvoid formView1_ModeChanged(object sender,EventArgs e)

{

if (formView1.CurrentMode ==FormViewMode.Insert || formView1.CurrentMode ==FormViewMode.Edit)

{

Master.ScriptManager1.SetFocus(formView1.FindControl("ddl_iWantFocused"));

}

}

Works great for selecting any other control in the form, but not the one populated with the CascadingDropDown.

Any help on how to set focus on this?

Let me revise that. I can SetFocus on other DropDownLists that don't use the CascadingDropDownList extender, but haven't been able to SetFocus on a Textbox.

Wednesday, March 21, 2012

how can i restate the focus inside updatepanel

hi,

i have several web controls inside a update panel. But i don't know how to set it so that right after my page come back from a callback, it will lost the focus. i tryed .focus() in asp.net, but it doesn't work... help anyone?

Alan,

after the focus method, try the upatepanel's Update() method.

it should work, although, i hide the same headache.

lblRowCount.Text = gridview1.Rows.Count.ToString();

txtProduitID.Focus();

pnlProduit.Update();

in this sample code, txtproduitID is the textbox where i type in the product code. and pnlProduit is the update panel.
this works for me.

regards,
formationusa


I tried that but it didnt work. Here is my code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void btn_Click(object sender, EventArgs e) { txt1.Text = DateTime.Now.ToString(); txt1.Focus(); up2.Update(); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <atlas:ScriptManager ID="scriptmanager" EnablePartialRendering="true" runat="Server" /> <atlas:UpdatePanel runat="server" ID="up2" Mode="Conditional"> <ContentTemplate> <asp:TextBox runat="server" ID="txt1"></asp:TextBox> <asp:Button runat="server" ID="btn" Text="Button" OnClick="btn_Click" /> </ContentTemplate> </atlas:UpdatePanel> </form></body></html>

Can you tell me what im doing wrong?


your syntax is correct, it seems to be something which will need more time. i tested your sample, and got the same problem. Also, in the forms i worked on, I have different conditions for setting the focus on the textboxes.
I will keep checking on this problem in more detail.

if others experience the same, please post.

regards,
formationusa


I have the same problem, but I want to set the focus AFTER the UpdatePanel has returned because it is adding the field I want to focus. I've tried using a client-side timeout to wait for the UpdatePanel to finish, but the time would change from one browser/client to another.

Is there a way to tell an UpdatePanel to execute a client-side method after it has updated?


setting the focus in AJAX seems to be working with Fireworks and not IE, please will that be fixed for future releases as its very crucial to have working properly for data entry Web pages.
Sorry, I meant Firefox browser and not fireworks, my apology.