Setting the focus on a control after an async postback
I already had a post prepared on how to set the focus on a control after an async postback. Unfortunately, it went directly to "garbadge" since now it's all too easy: we can do that by using the new SetFocusmethod exposed by the ScriptManager class. Here's a demo page that does just that!
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void h(object sender, EventArgs e)
{
manager.SetFocus(info);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asP:Scriptmanager runat="server" id="manager" />
<asp:UpdatePanel runat="server" ID="panel">
<ContentTemplate>
<asp:TextBox runat="server" ID="info" />
<asp:Button runat="server" ID="bt" Text="focus" OnClick="h" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>