Default button on an Update Panel

I have a page within a web application that contains four update panels.  I would like to set the default button of each update panel, but I am not sure how.

Any guidance would be greatly appreciated.
shanemayAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

XGISCommented:
Hey There,

I would just like to clarify, you have multiple <asp:Panels on your page each panel has a number of buttons you want to be able to set a default button in each panel when the panel is active or are the also text boxes in each panel that will require the default button???

i.e. will the end user click in the panel and press enter; or will the user type some thing in a textbox in each panel the press enter?
0
shanemayAuthor Commented:
No, not panels, Update Panels : <asp:UpdatePanel>,
Each panel has a form fields and a submit button, I would like to set the default button for each update panel to the appropriate submit button.  This would allow the user to enter information and hit the enter key on the keyboard.  

I can do this with asp:Panels using the defualtbutton attribute (<asp:Panel runat="server" DefaultButton="SubmitCommand">), however, it does not seem that update panels have this option.  
0
Edgard YamashitaSystems AnalystCommented:
just add a panel inside each updatepanel and set the defaultbutton to the id of the button inside the updatepanel that you want to be the default.. eg:



        <asp:UpdatePanel ID="updMain" runat="server">
            <ContentTemplate>
                <asp:Panel ID="pnlMain" runat="server" DefaultButton="Button1">
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

XGISCommented:
try this

           <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
             
            <asp:Button ID="Button2" runat="server" Text="Not Default" />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Default" />
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{

    protected void Button1_Click1(object sender, EventArgs e)
    {
       Label3.Text = "Default button pressed.  Time is " + DateTime.Now.ToString();
    }
}

Open in new window

0
XGISCommented:
or try this

<!--aspx-->

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<script language="javascript" type="text/javascript">
    function WebForm_FireDefaultButton(event, target) {
        if (event.keyCode == 13) {
            var src = event.srcElement || event.target;
            if (!src || (src.tagName.toLowerCase() != "textarea")) {
                var defaultButton;
                if (__nonMSDOMBrowser) {
                    defaultButton = document.getElementById(target);
                }
                else {
                    defaultButton = document.all[target];
                }
                if (defaultButton && typeof (defaultButton.click) != "undefined") {
                    defaultButton.click();
                    event.cancelBubble = true;
                    if (event.stopPropagation) event.stopPropagation();
                    return false;
                }
            }
        }
        return true;
    }
</script>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Panel ID="Panel1" runat="server" DefaultButton="Button2">
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Width="400px"></asp:TextBox>
                    <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Default" />
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
        </asp:Panel>
        <asp:Panel ID="Panel2" runat="server" DefaultButton="Button3">
            <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                <ContentTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Width="400px"></asp:TextBox>
                    <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Default" />
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
        </asp:Panel>
        <asp:Panel ID="Panel3" runat="server" DefaultButton="Button1">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                <asp:TextBox ID="TextBox3" runat="server" Width="400px"></asp:TextBox>
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Default" />
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
        </asp:Panel>
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox3.Text = "Default button pressed.  Time is " + DateTime.Now.ToString();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "Default button pressed.  Time is " + DateTime.Now.ToString();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        TextBox2.Text = "Default button pressed.  Time is " + DateTime.Now.ToString();
    }

}

Open in new window

0
shanemayAuthor Commented:
Thank you, that worked perfectly.  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.