Question

i'm dynamically generating asp controls inside an update panel on a certain trigger. However, when the text control is generated, the focus goes on to the next pre-existing element and screws things up. Is there a way I can trigger a javascript event after the update panel has been updated?

Was it helpful?

Solution

The following worked when the control wasn't added though a async postback.

In the aspx/ascx control.

<asp:PlaceHolder runat="server" ID="placeHolder1"></asp:PlaceHolder>

In the codebehind.

TextBox test = new TextBox();
test.ID = "test";
test.TabIndex = 21;
test.Text = "test";
placeHolder1.Controls.Add(test);
string script = "document.getElementById('" + test.ClientID + "').focus();";
ScriptManager.RegisterStartupScript(this, typeof(TextBox), UniqueID, script, true);

It seems that the async postback sets the focus on the page. Pressing tab put the focus on the text Textbox.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top