从code-背后刷新buttonclick一个UpdatePanel [英] Refresh an updatepanel on buttonclick from code-behind
问题描述
我使用的GridView正在使用的数据源和放大器;数据绑定。当我重新加载页面的GridView控件被更新,但我想这是对buttonclick,但它不是为我工作。
I'm using a Gridview that is using datasource & databinding. When i reload the page the gridview is updated but I want it to be on the buttonclick, but it's not working for me.
在UpdatePanel内GridView的:
The gridview inside the updatepanel:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="upWall" runat="server" ChildrenAsTriggers="true" UpdateMode="conditional">
<ContentTemplate>
<asp:GridView ID="gvWallPosts" runat="server" AutoGenerateColumns = "false"
CaptionAlign="NotSet" CellPadding="5">
<Columns>
<asp:TemplateField HeaderText="Avsändare">
<ItemTemplate>
<%# GetSender((int)Eval("WallSender"))%>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Inlägg">
<ItemTemplate>
<%# Eval("Post")%>
<br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:TextBox ID="txtWall" runat="server" Height="105px" TextMode="MultiLine" Width="227px"></asp:TextBox>
<br />
<asp:Button ID="btnWall" runat="server" Text="Posta" onclick="btnWall_Click" />
code-背后:
Code-behind:
protected void btnWall_Click(object sender, EventArgs e)
{
con.SendWallPost(con.GetId(Membership.GetUser().UserName), Convert.ToInt32(Request.QueryString["ID"]), txtWall.Text); //This method is sending the post
upWall.Update();
}
所以,我想在UpdatePanel上的ButtonClick更新,我不想重新加载整个页面看到的结果。
So, I want the updatepanel to be updated on the ButtonClick, I don't want to reload the whole page to see the result
推荐答案
由于我没有看到按钮 btnWall
,我认为它的<$ C之外$ C>的UpdatePanel 。
但是,你需要定义一个明确的触发,如果你想允许外部的控制的UpdatePanel
来触发回发。
Since i don't see the button btnWall
, i assume that it's outside of the UpdatePanel
.
But you need to define an explicit trigger if you want to allow a control outside of an UpdatePanel
to trigger a postback.
因此,您可以使用 AsyncPostBackTrigger
:
Therefore you can use an AsyncPostBackTrigger
:
<asp:UpdatePanel ID="upWall" runat="server" ChildrenAsTriggers="true" UpdateMode="conditional">
<ContentTemplate>
....
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnWall" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
这篇关于从code-背后刷新buttonclick一个UpdatePanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!