Search

DefaultButton in Panel For Wizard Errs by Nathan-Vindicator

Active

4
0
Sign in
to vote
Type: Bug
ID: 103530
Opened: 7/3/2005 1:50:29 PM
Access Restriction: Public
0
Workaround(s)
2
User(s) can reproduce this bug
Similar to the topics seen (eg, FDBK25934)
"Page.Form.DefaultButton = ((Button)(Wizard1.FindControl("StartNavigationTemplateContainerID").FindControl("StartNextButton"))).UniqueID;"

That works fine for the Page.Form. Even for a Login Control, you can use the format Login1$LoginButton.
But trying to set the DefaultButton in a Panel for a Wizard's Navigation Button causes an error.
Details (expand)
Product Language
English
Version
Visual Studio 2005 Beta 2
Category
Controls
Operating System
Windows XP Professional
Operating System Language
US English
Steps to Reproduce
Plop a Wizard inside a Panel and either in code-behind or html code, set the Panel's DefaultButton.
For the sake of coding ease, create the Wizard's Templates and the for the Buttons, set the ID for MoveNext and MoveComplete to "NextButton", thereby allowing you to set the Panel's DefaultButton only once as "NextButton".
Actual Results
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: The DefaultButton of 'Panel' must be the ID of a control of type IButtonControl.
Expected Results
no error. Wizard's MoveNext fires as DefaultButton
Sign in to post a comment.
Posted by Erakis on 10/17/2010 at 5:13 PM
It is very annoying because I will have to link javascript function to catch the <enter> key instead of using the actual fonctionnality of the UpdatePanel (DefautlButton) !!! Why offers the DefaultButton property if it doesn't works properly and there is no workaround ?

Here is a way to reproduce the bug.

<asp:updatepanel id="upnlTauxHoraireList" runat="server" updatemode="Conditional">
<contenttemplate>
    <asp:panel id="pnTauxHoraireList" runat="server" onrowdatabound="grvwTauxHoraire_RowDataBound">
        <ctaqmanager:gridviewex id="grvwTauxHoraire"             runat="server" >
            <columns>
                <asp:templatefield headertext="-" headerstyle-horizontalalign="left" itemstyle-horizontalalign="left" headerstyle-wrap="false" itemstyle-wrap="false" footerstyle-wrap="false">
                    <itemtemplate>
                        <asp:imagebutton id="imgbtSupprimer" runat="server" imageurl="~/Images/delete.gif" width="12" height="12" cssclass="gridImageButton" alternatetext="Supprimer ce taux horaire" tooltip="Supprimer ce taux horaire" commandname="Supprimer" causesvalidation="false" />
                        <asp:imagebutton id="imgbtEdit" runat="server" imageurl="~/Images/edit.gif" width="12" height="12" cssclass="gridImageButton" alternatetext="Éditer ce taux horaire" tooltip="Éditer ce taux horaire" commandname="Editer" />
                    </itemtemplate>
                    <edititemtemplate>
                        <asp:imagebutton id="imgbtAnnuler" runat="server" imageurl="~/Images/cancel.gif" width="12" height="12" cssclass="gridImageButton" alternatetext="Annuler l'édition de ce taux horaire" tooltip="Annuler l'édition de ce taux horaire" commandname="Annuler" />
                        <asp:imagebutton id="imgbtMiseAJour" runat="server" imageurl="~/Images/insert.gif" width="12" height="12" cssclass="gridImageButton" alternatetext="Mise à jour de ce taux horaire" tooltip="Mise à jour de ce taux horaire" commandname="MiseAJour" validationgroup="TauxHoraire" causesvalidation="true" />
                        <asp:button id="btMiseAJour" runat="server" style="display :none;" causesvalidation="true" validationgroup="TauxHoraire" commandname="MiseAJour" />
                    </edititemtemplate>
                </asp:templatefield>
                </columns>
        </asp:panel>
</contenttemplate>
</asp:updatepanel>



protected void grvwTauxHoraire_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (((e.Row.RowState & DataControlRowState.Edit) != 0))
        {
            pnTauxHoraireList.DefaultButton = ((Button)e.Row.FindControl("btMiseAJour")).UniqueID;
        }
    }
}



Posted by Microsoft on 8/5/2010 at 11:36 AM
Erik,

Could you try using ButtonPathologySearch.UniqueID?

We have tried your page and could get the error message using ID, but switching to UniqueID seems to work.

Here is the working page we tested (with a corresponding master page):

<%@ Page Language="C#" Debug="true" MasterPageFile="~/MasterPage.master" %>
<script runat="server">    
    protected void Page_Load(object sender, EventArgs e) {
        Page.Form.DefaultButton = ButtonPathologySearch.UniqueID;
    }

    protected void ButtonPathologySearch_Click(object sender, EventArgs e) {
    }
</script>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:TextBox ID="txtSearchText" runat="server" CssClass="txtMedium" TabIndex="3"></asp:TextBox>
    <asp:RequiredFieldValidator ID="ReqSearchText" runat="server" ControlToValidate="txtSearchText"
        ErrorMessage="*"></asp:RequiredFieldValidator>
    <asp:Button ID="ButtonPathologySearch" Text="Search" CssClass="button" runat="server"
        OnClick="ButtonPathologySearch_Click" />
</asp:Content>

Thanks.
Posted by Erik Sargent on 7/9/2010 at 12:59 PM
I've experienced this same error without involving the wizard. Just the simple line:
Page.Form.DefaultButton = ButtonPathologySearch.ID;
on the aspx page that uses a master page.

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContentPlaceHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <link href="App_Themes/Main/Main.css" rel="stylesheet" type="text/css" />
    <link rel="Stylesheet" href="style/style.css" type="text/css" media="screen" />
    <div>
        <div class="header">
            <uc1:StatusMessage ID="StatusMessage1" runat="server" />
        </div>
        <div class="mainContent">
            <div class="divCol1">
                <asp:TextBox ID="txtSearchText" runat="server" CssClass="txtMedium" TabIndex="3"></asp:TextBox>
                <asp:RequiredFieldValidator ID="ReqSearchText" runat="server" ControlToValidate="txtSearchText"
                    ErrorMessage="*"></asp:RequiredFieldValidator>
                <asp:Button ID="ButtonPathologySearch" Text="Search" CssClass="button" runat="server"
                    OnClick="ButtonPathologySearch_Click" />

At the very least, the documentation for the method on MSDN needs updating to explain how to use it correctly since this is the obvious usage. This could also be done out-of-band for the release.

BTW, this is a version .NET 3.5 app.
Posted by Microsoft on 6/18/2010 at 1:12 PM
We have re-activated this bug and we are investigating the number of people affected by this issue.
Posted by Microsoft on 3/21/2006 at 3:25 PM
Thank you for your feedback. We are investigating this issue.

Thank you, Visual Studio Product Team.
Posted by Microsoft on 11/29/2005 at 5:58 PM
This issue has been reactivated as we begin planning for the next version of Visual Studio and the .NET Framework. Over the coming months we will reconsider feedback that was previously postponed. We welcome your comments and participation in this process. See http://blogs.msdn.com/productfeedback/archive/2005/10/21/483563.aspx for more information.

- The Developer Division
Posted by Microsoft on 8/2/2005 at 11:10 AM
Sorry but this issue given the stage in the product cycle we are in won't get fixed.
Posted by Microsoft on 7/29/2005 at 12:55 PM
For the time being, you can work around this issue by using an id that's relative to the naming container instead of the UniqueID which is relative to the Page:
            string containerID = Panel1.NamingContainer.UniqueID;
            string globalButtonID = Wizard1.FindControl("StartNavigationTemplateContainerID").FindControl("NextButton").UniqueID;
            string localButtonID = globalButtonID.Substring(containerID.Length + 1);
            Panel1.DefaultButton = localButtonID;

We're considering a fix in Panel, but considering that we're in the last stages of the product cycle, I hope you'll understand that it may be postponed to the next version of the product.

Thank you for your feedback,
Bertrand Le Roy
Web Platform and Tools
Posted by Nathan-Vindicator on 7/27/2005 at 3:02 PM
Ok, I found that very curious, but realized the the error occurs when I am using a MasterPage for that page.
I would have thought the UniqueID would take that into account as it looks to:
ctl00$ContentPlaceHolder1$Wizard1$StepNavigationTemplateContainerID$NextButton

But it still errs.
Posted by Microsoft on 7/11/2005 at 10:01 AM
Thanks for writing back but to be honest I am not really sure what you are asking for.... to try and help I am attaching the code for an entire page that does what I think you are trying to do.... I hope this helps.

<%@ Page Language="C#" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">    
    protected void Wizard1_ActiveStepChanged(object sender, EventArgs e)
    {
        if (Wizard1.ActiveStep == WizardStep1)
            Panel1.DefaultButton = Wizard1.FindControl("StartNavigationTemplateContainerID").FindControl("NextButton").UniqueID;
        else if (Wizard1.ActiveStep == WizardStep2)
            Panel1.DefaultButton = Wizard1.FindControl("StepNavigationTemplateContainerID").FindControl("NextButton").UniqueID;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)            
            Panel1.DefaultButton = Wizard1.FindControl("StartNavigationTemplateContainerID").FindControl("NextButton").UniqueID;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="Panel1" runat="server" Height="150px" Width="525px">
            <asp:Wizard ID="Wizard1" runat="server" OnActiveStepChanged="Wizard1_ActiveStepChanged">
                <WizardSteps>
                    <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    </asp:WizardStep>
                    <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">
                        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                    </asp:WizardStep>
                    <asp:WizardStep ID="WizardStep3" runat="server" Title="Step 3">
                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                    </asp:WizardStep>
                </WizardSteps>
                <StartNavigationTemplate>
                    <asp:Button ID="NextButton" runat="server" CommandName="MoveNext" Text="Next" />
                </StartNavigationTemplate>
                <StepNavigationTemplate>
                    <asp:Button ID="StepPreviousButton" runat="server" CausesValidation="False" CommandName="MovePrevious"
                        Text="Previous" />
                    <asp:Button ID="NextButton" runat="server" CommandName="MoveNext" Text="Next" />
Posted by Nathan-Vindicator on 7/7/2005 at 10:20 AM
Right, I was afraid that using the entire tree path for the NextButton would be required and figured it wouldn't work for me in the the Design Code considering it would be dependant on the current Template ID.
That is why I coded the change in the Wizard's ActiveStepChanged Event:
        If (Me.Wizard1.ActiveStep Is Me.WizardStep2) Then
            Me.TextBox1.Focus()
            Me.Panel1.DefaultButton = Me.Wizard1.FindControl("StartNavigationTemplateContainerID").FindControl("NextButton").UniqueID

        ElseIf (Me.Wizard1.ActiveStep Is Me.WizardStep2) Then
....
which still gave me the same error
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: The DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl
Posted by Microsoft on 7/6/2005 at 9:25 PM
We have investigated your issue further and think the problem might be that you are using the control ID from the aspx page not the unique ID generated for Wizard at runtime.

In your bug report you say
"set the ID for MoveNext and MoveComplete to "NextButton", thereby allowing you to set the Panel's DefaultButton only once as "NextButton"."

Setting Panel's uniqueID as NextButton will reaise the exception as its not a uniqueID. Actually you need to set the uniqueIds generated for the defaultButton Property of the panel. Here is one sample that is using uniqueId and it working as expected.

<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px" DefaultButton="Wizard1$StartNavigationTemplateContainerID$NextButton">
            <asp:Wizard ID="Wizard1" runat="server">
                <WizardSteps>
                    <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
                    </asp:WizardStep>
                    <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">
                    </asp:WizardStep>
                </WizardSteps>
                <StartNavigationTemplate>
                    <asp:Button ID="NextButton" runat="server" CommandName="MoveNext" Text="Next" />
                </StartNavigationTemplate>
                <FinishNavigationTemplate>
                    <asp:Button ID="FinishPreviousButton" runat="server" CausesValidation="False" CommandName="MovePrevious"
                        Text="Previous" />
                    <asp:Button ID="NextButton" runat="server" CommandName="MoveComplete" Text="Finish" />
                </FinishNavigationTemplate>
            </asp:Wizard>
        </asp:Panel>

Thanks
The Web Platform and Tools Team
Posted by Microsoft on 7/5/2005 at 10:49 AM
Thanks for submitting this issue -- we are currently investigating and will keep you posted.

Thanks
The Web Platform and Tools Team
Sign in to post a workaround.