当用户点击按钮时,我试图在没有回发的情况下制作我网站的某个部分。 我使用Ajax通过asp.net(Placed ScriptManager和UpdatePanel),我知道我需要在ContentTemplate中提供我的内容,但似乎我不能,因为我有一个“Div”......
这是我的代码,没有内容模板:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<p>
Some Text</p>
<p>
If you dont have a username yet, you can register <a href="Register.aspx">here</a></p>
<div id="LeftDiv">
<asp:TextBox ID="HowMany" runat="server"></asp:TextBox>
<br />
<br />
<asp:Panel ID="Panel2" runat="server">
<asp:Button ID="StartToGenerateButton" runat="server" Text="I know it!"
OnClick="StartToGenerateButton_Click" />
</asp:Panel>
<br />
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter your discovery"
ControlToValidate="HowMany" Display="Dynamic" ForeColor="Red"
Font-Bold="True" Font-Size="Small"></asp:RequiredFieldValidator>
<br />
</div>
<!--LeftDiv-->
<div id="RightDiv">
<asp:ListBox ID="ListBox" runat="server" Height="200px" Width="120px"></asp:ListBox>
<br />
<br />
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="youWon" runat="server" onclick="youWon_Click" Text="You Won!" />
</asp:Panel>
<asp:Label ID="ErrorMessege" runat="server" ForeColor="Red"></asp:Label>
</div><!--RightDiv-->
<div class="clearBoth">
</div><!--clearBoth-->
</asp:UpdatePanel>
我该怎么办呢?
答案 0 :(得分:3)
这是你的意思吗?
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- your content goes here -->
</ContentTemplate>
</asp:UpdatePanel>
您可以将整个内容(包括div)放在更新面板的内容面板中。内容模板区域中的任何内容都将独立于主页面进行回发。您将获得部分回发。 这有帮助吗?
修改强>
要从其外部的控件触发面板的回发,则需要使用更新面板的回发触发器元素来指定应触发更新的控件
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
... UpdatePanel Content ...
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnDemoButtonInDiv" />
</Triggers>
</asp:UpdatePanel>
。 有关(详尽的)详细信息,请参阅此MS article