protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
{
string bn = Request.Browser.Browser;
if (bn.Equals("Firefox"))
{
this.ScriptManager1.SetFocus(gvBatch);
}
else
{
this.ScriptManager1.SetFocus(gvBatch);
}
if (ddlCourse.SelectedItem.Text == "-Select-")
{
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Select the course'); }", true);
this.ScriptManager1.SetFocus(ddlCourse);
gvBatch.Visible = false;
}
else
{
Session["Course_Id"] = ddlCourse.SelectedValue;
gvBatch.Visible = true;
fillBatchGrid();
}
}
in aspx page
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Selected="True">item1</asp:ListItem>
<asp:ListItem>item2</asp:ListItem>
<asp:ListItem>item3</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<div style="display:none;">
<asp:TextBox ID="hidden" runat="server"></asp:TextBox>
</div>
In code bind
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Attributes.Add("onkeyup", "document.getElementById('hidden').focus();document.getElementById('DropDownList1').focus();");
DropDownList1.Attributes.Add("onkeydown", "document.getElementById('hidden').focus();document.getElementById('DropDownList1').focus();");
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.SelectedItem.Text;
DropDownList1.Focus();
}