精确地把asp的UpdatePanel控件放在窗体的哪里?

问题描述:

我是ASP.NET新手。我有下面的代码,但我不知道在哪里放置asp:UpdatePanel控件,它的contenttemplate和(如果需要)它的触发器,所以我可以有一个验证没有回发?精确地把asp的UpdatePanel控件放在窗体的哪里?

<form method="post" id="formLogin" runat="server"> 
    <asp:ScriptManager runat="server"> 
     <Scripts> 
      // bunch of scriptreferences 
     </Scripts> 
    </asp:ScriptManager> 

       <p> 
        <asp:Label ID="lblEmail" runat="server" Text="Email:"/><br/> 
        <asp:TextBox ID="txtEmail" runat="server"/> 
       </p> 
       <p> 
        <asp:Label ID="lblPassword" runat="server" Text="Password:"/><br/> 
        <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"/> 
       </p> 

     <div id="msg" runat="server" class="item"> 

        <asp:Label ID="lblMessage" runat="server" ForeColor="Red" /> 
       </div> 

       <div class="loginbutton"> 
        <p> 
         <a href="#" class="forgot">Forgot Password?</a><br /> 
         <a href="../EN/form_1.aspx" class="forgot">New user?</a> 
        </p> 
        <input type="reset" name="login" value="Cancel" id="cancel" /> 

        <asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" /> 
       </div> 
    </form> 

如果证书与数据库记录不匹配,lblMessage将显示为“您输入了错误的电子邮件/密码”。

系统规定:

它不应该在网页的<asp:ScriptManager>标记之前出现。

您的需要:

,你只需要在某个事件被触发要更新所有部件应放在UpdatePanel<ContentTemplate>标签内。

下例:

<div> 
    <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
    <asp:Label ID="lblDontUpdateMe" runat="server" /> 
    <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
     <ContentTemplate> 
      <asp:Label ID="lblUpdateMe" runat="server" /> 
      <asp:Button ID="btnUpdate" runat="server" Text="Update" /> 
     </ContentTemplate> 
    </asp:UpdatePanel> 
</div> 

对于你的问题:

<form method="post" id="formLogin" runat="server"> 
    <asp:ScriptManager runat="server"> 
     <Scripts> 
      // bunch of scriptreferences 
     </Scripts> 
    </asp:ScriptManager> 
    <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
     <ContentTemplate> 
      <p> 
       <asp:Label ID="lblEmail" runat="server" Text="Email:"/><br/> 
       <asp:TextBox ID="txtEmail" runat="server"/> 
      </p> 
      <p> 
       <asp:Label ID="lblPassword" runat="server" Text="Password:"/><br/> 
       <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"/> 
      </p> 

      <div id="msg" runat="server" class="item"> 

       <asp:Label ID="lblMessage" runat="server" ForeColor="Red" /> 
      </div> 

      <div class="loginbutton"> 
       <p> 
        <a href="#" class="forgot">Forgot Password?</a><br /> 
        <a href="../EN/form_1.aspx" class="forgot">New user?</a> 
       </p> 
       <input type="reset" name="login" value="Cancel" id="cancel" /> 

       <asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" /> 
      </div> 
     </ContentTemplate> 
    </asp:UpdatePanel> 
</form>