Share via


PasswordRecovery.QuestionTemplate 属性

定义

获取或设置用于显示 PasswordRecovery 控件的“提示问题”视图的模板。

public:
 virtual property System::Web::UI::ITemplate ^ QuestionTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.PasswordRecovery))]
public virtual System.Web.UI.ITemplate QuestionTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.PasswordRecovery))>]
member this.QuestionTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property QuestionTemplate As ITemplate

属性值

ITemplate,包含用于在“提示问题”视图中显示 PasswordRecovery 控件的模板。 默认值为 null

属性

示例

下面的代码示例演示问题视图的默认模板。

重要

此示例包含一个接受用户输入的文本框,这是一个潜在的安全威胁。 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。 有关详细信息,请参阅脚本侵入概述

<%@ page language="VB" %>

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

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
    <asp:passwordrecovery id="PasswordRecovery1" runat="server">
        <questiontemplate>
            <table border="0">
                <tr>
                    <td align="Center" colspan="2">Identity Confirmation</td>
                </tr>
                <tr>
                    <td align="Center" colspan="2">Answer the following question to receive your password.</td>
                </tr>
                <tr>
                    <td align="Right">User Name:</td>
                    <td>
                        <asp:literal runat="server" id="UserName"></asp:literal>
                    </td>
                </tr>
                <tr>
                    <td align="Right">Question:</td>
                    <td>
                        <asp:literal runat="server" id="Question"></asp:literal>
                    </td>
                </tr>
                <tr>
                    <td align="Right">Answer:</td>
                    <td>
                        <asp:textbox runat="server" id="Answer"></asp:textbox>
                        <asp:requiredfieldvalidator runat="server" controltovalidate="Answer" errormessage="Answer." id="AnswerRequired">*</asp:requiredfieldvalidator>
                    </td>
                </tr>
                <tr>
                    <td align="Right" colspan="2">
                        <asp:button runat="server" commandname="Submit" text="Submit" id="Button"></asp:button>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="color:Red;">
                        <asp:literal runat="server" id="FailureText"></asp:literal>
                    </td>
                </tr>
            </table>
        </questiontemplate>
    </asp:passwordrecovery>

</form>
</body>
</html>
<%@ page language="C#" %>

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

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
    <asp:passwordrecovery id="PasswordRecovery1" runat="server">
        <questiontemplate>
            <table border="0">
                <tr>
                    <td align="Center" colspan="2">Identity Confirmation</td>
                </tr>
                <tr>
                    <td align="Center" colspan="2">Answer the following question to receive your password.</td>
                </tr>
                <tr>
                    <td align="Right">User Name:</td>
                    <td>
                        <asp:literal runat="server" id="UserName"></asp:literal>
                    </td>
                </tr>
                <tr>
                    <td align="Right">Question:</td>
                    <td>
                        <asp:literal runat="server" id="Question"></asp:literal>
                    </td>
                </tr>
                <tr>
                    <td align="Right">Answer:</td>
                    <td>
                        <asp:textbox runat="server" id="Answer"></asp:textbox>
                        <asp:requiredfieldvalidator runat="server" controltovalidate="Answer" errormessage="Answer." id="AnswerRequired">*</asp:requiredfieldvalidator>
                    </td>
                </tr>
                <tr>
                    <td align="Right" colspan="2">
                        <asp:button runat="server" commandname="Submit" text="Submit" id="Button"></asp:button>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="color:Red;">
                        <asp:literal runat="server" id="FailureText"></asp:literal>
                    </td>
                </tr>
            </table>
        </questiontemplate>
    </asp:passwordrecovery>

</form>
</body>
</html>

注解

属性 QuestionTemplate 包含用于在问题视图中定义控件外观的 PasswordRecovery 模板。

下表列出了问题视图模板中使用的必需控件和可选控件。

ID 或命令名称 控件类型 必需/可选
Answer 实现 的任何 IEditableTextControl控件。 必需
Submit 任何导致事件浮升的控件。 可选

Submit 控件可以是导致事件浮升的任何控件,例如 ButtonLinkButtonImageButton。 控件的命令名称属性必须设置为“Submit”。

如果“问题”视图不包含所需的控件,则 PasswordRecovery 控件将引发 HttpException 异常。 如果向错误类型的控件提供可选控件 ID,则不会引发异常;但是,控件随后会被 PasswordRecovery 该控件忽略。

使用模板定义问题视图的外观时,只有以下属性会影响控件的行为:

将模板用于“问题”视图时,所有其他属性都处于非活动状态。

适用于

另请参阅