从CompleteWizardStep获取对象(FileUpload)

本文关键字:FileUpload 取对象 CompleteWizardStep 获取 | 更新日期: 2023-09-27 18:28:35

CreateUserWizardCompleteWizardStep内的C#代码后面的事件ButtonImagem_Click上尝试访问FileUpload时遇到困难。

我的代码在哪里:

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" OnCreatedUser="CreateUserWizard1_CreatedUser">
    <WizardSteps>
        <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" Title="Criar conta">
            <ContentTemplate>
                <%--...--%>
            </ContentTemplate>
        </asp:CreateUserWizardStep>
        <asp:CompleteWizardStep runat="server" ID="CompleteWizardStep1">
            <ContentTemplate>
                <asp:FileUpload ID="FileUpload1" runat="server" /><br />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FileUpload1" ErrorMessage=""></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FileUpload1" ErrorMessage="Apenas são aceites imagens." ValidationExpression="(.*'.([Gg][Ii][Ff])|.*'.([Jj][Pp][Gg])|.*'.([Bb][Mm][Pp])|.*'.([pP][nN][gG])|.*'.([tT][iI][iI][fF])$)"></asp:RegularExpressionValidator>
                <br /><asp:Button ID="ButtonImagem" runat="server" Text="Concluir" OnClick="ButtonImagem_Click" />
            </ContentTemplate>
        </asp:CompleteWizardStep>
    </WizardSteps>
</asp:CreateUserWizard>

从CompleteWizardStep获取对象(FileUpload)

找到了一个解决方案,只需要像这样添加ContentTemplateContainer

FileUpload FileU = (FileUpload)CompleteWizardStep1.ContentTemplateContainer.FindControl("FileUpload1");