从 CompleteWizardStep 获取对象 (FileUpload)
Posted
技术标签:
【中文标题】从 CompleteWizardStep 获取对象 (FileUpload)【英文标题】:Get an object (FileUpload) from a CompleteWizardStep 【发布时间】:2015-12-31 01:17:31 【问题描述】:我在尝试访问 ButtonImagem_Click
的事件 ButtonImagem_Click
时遇到困难,该事件位于 C# 后面的代码中,该事件位于 CreateUserWizard
上的 CompleteWizardStep
内。
我的代码在哪里:
<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>
【问题讨论】:
能否添加显示您尝试访问 FileUpload 控件的代码?也许here 建议的解决方案可能会有所帮助。 【参考方案1】:找到了解决办法,只需要像这样添加ContentTemplateContainer
:
FileUpload FileU = (FileUpload)CompleteWizardStep1.ContentTemplateContainer.FindControl("FileUpload1");
【讨论】:
以上是关于从 CompleteWizardStep 获取对象 (FileUpload)的主要内容,如果未能解决你的问题,请参考以下文章