D
David Beardsley
My web form has one edit box, a button, a list box and a combo box.
When the button is clicked the text in the edit box is added to the
list box and the combo box. After the new text is added I want to
clear the text of the edit box and set focus back to the text box.
I setup the event here:
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
btnAdd.Attributes.Add("OnClick", ECMA.SetFocus("txtNewItem"));
}
}
Relevant html output:
<input name="txtNewItem" type="text" id="txtNewItem" />
<input name="TextBox2" type="text" id="TextBox2" style />
<select name="cbItem" id="cbItem">...</select>
<input type="submit" name="btnAdd" value="Add" id="btnAdd"
OnClick="document.getElementById('txtNewItem').focus();"/>
<select name="lbItem" size="4" id="lbItem">...</select>
When I run the application the focus is not set as desired. What
appears to happen is the focus is set momentarily, then the postback
event fires and the focus shifts again.
My question is, how do you properly manage the client side focus
around the postback events?
TIA!
David Beardsley
When the button is clicked the text in the edit box is added to the
list box and the combo box. After the new text is added I want to
clear the text of the edit box and set focus back to the text box.
I setup the event here:
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
btnAdd.Attributes.Add("OnClick", ECMA.SetFocus("txtNewItem"));
}
}
Relevant html output:
<input name="txtNewItem" type="text" id="txtNewItem" />
<input name="TextBox2" type="text" id="TextBox2" style />
<select name="cbItem" id="cbItem">...</select>
<input type="submit" name="btnAdd" value="Add" id="btnAdd"
OnClick="document.getElementById('txtNewItem').focus();"/>
<select name="lbItem" size="4" id="lbItem">...</select>
When I run the application the focus is not set as desired. What
appears to happen is the focus is set momentarily, then the postback
event fires and the focus shifts again.
My question is, how do you properly manage the client side focus
around the postback events?
TIA!
David Beardsley