将链接按钮放置在更新面板内,不触发链接按钮的点击事件
本文关键字:链接 按钮 事件 更新 | 更新日期: 2023-09-27 17:59:52
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager<asp:UpdatePanel ID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:Timer runat="server" ID="Timer2" Interval="60" ontick="Timer1_Tick"/>
<asp:DataList ID="DataList1" runat="server" RepeatColumns="1" onitemcommand="DataList1_ItemCommand">
<ItemTemplate>
<b>Test Name:</b> <%# DataBinder.Eval(Container.DataItem, "Name")%> <br />
<b>Test Phone:</b> <%# DataBinder.Eval(Container.DataItem, "Phone")%> <br />
<asp:LinkButton ID="btnView" runat="server" Text="View" CommandName="ShowDetails" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Name")%>' OnCommand="btnView_Command"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Panel ID="panel2" runat="server" Visible="false"></asp:Panel>
Code Behind :
protected void dlBundleRequests_ItemCommand(object source, DataListCommandEventArgs e)
{
panel1.Visible = false;
panel2.Visible = true;
if (e.CommandName == "ShowDetails")// null)
{
Session["Name"] = e.CommandArgument.ToString();
//Show Panel2
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
//Binding DataList1
}
protected void btnView_Command(Object sender, CommandEventArgs e)
{
//set visibility true for Panel2
}
添加updatepanel&计时器控制是每5分钟自动刷新一次数据表1。请帮我摆脱困境。添加这两个控件后,链接按钮将停止工作。
试试这个。。
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnView"/>
</Triggers>
您必须在链接按钮标签中设置CommandArgument和CommandName,然后使用命令事件而不是单击
<ItemTemplate>
<b>Test Name:</b> <%# DataBinder.Eval(Container.DataItem, "Name")%> <br />
<b>Test Phone:</b> <%# DataBinder.Eval(Container.DataItem, "Phone")%> <br />
<asp:LinkButton ID="btnView" runat="server" Text="View" OnCommand="btnView_Click" CommandName="ShowDetails" CommandArgument='%# DataBinder.Eval(Container.DataItem, "Phone")%' ></asp:LinkButton>
</ItemTemplate>
然后在codebehind中处理该参数。。MSDN 中的CommandArgument