Wednesday, March 21, 2012

defaultbutton, defaultfocus and UpdatePanel

Looks like defaultbutton and defaultfocus properties of the asp.net <form> do not work with UpdatePanel. Is there a workaround?

<

scriptrunat="server">protectedvoid Button1_Click(object sender,EventArgs e)

{

Label1.Text =

"You clicked the button1";

form1.DefaultButton =

"Button2";

}

protectedvoid Button2_Click(object sender,EventArgs e)

{

Label1.Text =

"You clicked the button2";

}

</

script>

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>Untitled Page</title>

</

head>

<

body><atlas:ScriptManagerID="sm1"runat="server"EnablePartialRendering="true"/><formid="form1"runat="server"defaultbutton="Button1"defaultfocus="TextBox1"><atlas:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:TextBoxID="TextBox1"runat="server"></asp:TextBox><asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/><asp:ButtonID="Button2"runat="server"OnClick="Button2_Click"Text="Button"/><asp:LabelID="Label1"runat="server"Text=""></asp:Label></ContentTemplate></atlas:UpdatePanel></form>

</

body>

</

html>

hello.

the only i've used with success was to handle the propertychanged event of the pagerequestmanager and check for the _inPostBack...if you search this forum, you'll see a similar thread with 15 to 20 posts that talks about this issue.


I am having the same problem and i am not able to locate the article with the search request that you have mentioned.

Can you please provide it to me please. This is the last hurdle for me before the release :(

Thanks a lot in advance.

Try this. It solved my problem

protectedvoid Page_Load(object sender,EventArgs e)

{

Page.Form.DefaultFocus = nameTextBox.ClientID;

Page.Form.DefaultButton = submitButton.UniqueID;

}

No comments:

Post a Comment