Sunday, 24 February 2013

How to set asp:CreateUserWizardas's CreateUserButton as default button of asp:Panel?



The Problem: Is to set CreateUserButton of <asp:CreateUserWizardas> as a DefaultButton of a <asp:Panel>. What to write in place of question marks of the next script? 

    <asp:Panel runat="server" ID="WizardPanel" DefaultButton="???????????????!!!!!!!!!!?">
<asp:CreateUserWizard ID="RegisterUser" runat="server" Width="449px" .......
.........................

<input type="submit" name="ctl00$ContentForm$RegisterUser$__CustomNav0$StepNextButtonButton" value="موافق" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentForm$RegisterUser$__CustomNav0$StepNextButtonButton&quot;, &quot;&quot;, true, &quot;RegisterUser&quot;, &quot;&quot;, false, false))" id="ctl00_ContentForm_RegisterUser___CustomNav0_StepNextButtonButton" class="myButton" />

</asp:CreateUserWizard>
    </asp:Panel>

[*]--------------------------------------------------------------------------------------------------
The following are some approaches that don't succeed: ... but number 4 is succeeded.
[1]--------------------------------------------------------------------------------------------------
Panel1.DefaultButton = ((Button)RegisterUserStep1.CustomNavigationTemplateContainer.FindControl("StepNextButton")).ID;
Description: 
Try to set DefaultButton programatically, but FindControl() returns nothing.
[2]--------------------------------------------------------------------------------------------------
    LookForDefaultButton(this.RegisterUser.Controls);
    protected bool LookForDefaultButton(ControlCollection collection)
    {
        foreach (Control ctrl in collection)
        {
            if (ctrl.GetType() == typeof(Button) && (ctrl as Button).ID == "StepNextButton1")
            {
                this.WizardPanel.DefaultButton = ctrl.UniqueID;
                return true;
            }
            else
                if (LookForDefaultButton(ctrl.Controls))
                    return true;

        }
        return false;
    }
Description: 
Try to set DefaultButton programatically, but <asp:Panel> issued exception of IButtonControl required.
[3]--------------------------------------------------------------------------------------------------
    <asp:Button ID="RegisterPanel" runat="server" style="display:none;" 
    ValidationGroup="RegisterUser" 
    CausesValidation="true"
    OnClientClick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentForm$RegisterUser$__CustomNav0$StepNextButtonButton&quot;, &quot;&quot;, true, &quot;RegisterUser&quot;, &quot;&quot;, false, false)); return;"
    />
Description: 
Try to Invok "WebForm_DoPostBackWithOptions" statment through a brooker button "RegisterUser", but causes a lot of problems with validation and postback.
[4]--------------------------------------------------------------------------------------------------
<div id="ctl00_ContentForm_WizardPanel" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ContentForm_RegisterUser___CustomNav0_StepNextButtonButton')">
Description:
Use <div> instead of <asp:Panel> to do the same job "Invoking WebForm_FireDefaultButton() at client" without a brooker button. All validation and postback done without any problem.

No comments:

Post a Comment