我在带有部分回发的更新面板中动态添加控件时遇到问题。我在后面的代码中动态生成一些 LinkButton 并设置它们的触发器,但是当我触发它们时,它们会完全回发,即使在我触发它们时也不会调用 LinkButton 事件.它们被放置在'divPageNumber'中
*.aspx:
</asp:DataList>
<table style="width: 100%">
<tr style="width: 10%">
<td>
<asp:LinkButton ID="lnkPrevious" runat="server" Font-Bold="True"
NavigateUrl="~/Default.aspx" OnClick="lnkPrevious_Click" Width="100px"><<صفحه قبل</asp:LinkButton>
</td>
<td style="width: 80%">
<div id="divPageNumber" dir="rtl" runat="server">
</div>
</td>
<td style="width: 10%">
<asp:LinkButton ID="lnkNext" runat="server" Font-Bold="True"
NavigateUrl="~/Default.aspx" OnClick="lnkNext_Click" Width="80px">صفحه بعد>></asp:LinkButton>
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Command"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="LinkButton2" EventName="Command" />
<asp:AsyncPostBackTrigger ControlID="LinkButton3" EventName="Command" />
<asp:AsyncPostBackTrigger ControlID="LinkButton4" EventName="Command" />
<asp:AsyncPostBackTrigger ControlID="LinkButton5" EventName="Command" />
<asp:AsyncPostBackTrigger ControlID="LinkButton6" EventName="Command" />
<asp:AsyncPostBackTrigger ControlID="LinkButton7" EventName="Command" />
<asp:AsyncPostBackTrigger ControlID="LinkButton0" EventName="Command" />
<asp:AsyncPostBackTrigger ControlID="btnSearchHead" EventName="Command" />
<asp:AsyncPostBackTrigger ControlID="LinkButton8" EventName="Command" />
<asp:AsyncPostBackTrigger ControlID="lnkNext" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lnkPrevious" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
和 *.cs:
LinkButton btnPage;
for (int i = 1; i <= objPagedDataSource.PageCount; i++)
{
btnPage = new LinkButton();
btnPage.ID = "btnPage" + i.ToString();
if (i == GetCurrentPageNumber + 1)
btnPage.Font.Bold = true;
btnPage.Width = 10;
btnPage.Style["margin-right"] = "2px";
btnPage.Style["margin-left"] = "2px";
btnPage.Text = i.ToString();
if (brand != "" && brand != null)
btnPage.PostBackUrl = "Default.aspx?brand=" + brand + "&Page=" + i.ToString();
else if (model != "" && model != null)
btnPage.PostBackUrl = "Default.aspx?model=" + model + "&Page=" + i.ToString();
else
btnPage.PostBackUrl = "Default.aspx?Page=" + i.ToString();
divPageNumber.Controls.Add(btnPage);
LinkButton lb = (LinkButton)divPageNumber.FindControl("btnPage" + i.ToString());
lb.Click += new EventHandler(lnkdel_OnClick);
//Creates a new async trigger
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = lb.UniqueID;
trigger.EventName = "Click";
UpdatePanel1.Triggers.Add(trigger);
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);
}
UpdatePanel1.Update();
protected void lnkdel_OnClick(object sender, EventArgs e)
{
}
protected void lnkPrevious_Click(object sender, EventArgs e)
{
//GetCurrentPageNumber -= 1;
//BindDataToRepeter();
Response.Redirect("Default.aspx?Page=" + (Convert.ToInt32(Page.Request["Page"]) - 1).ToString());
}
protected void lnkNext_Click(object sender, EventArgs e)
{
//GetCurrentPageNumber += 1;
//BindDataToRepeter();
Response.Redirect("Default.aspx?Page=" + (Convert.ToInt32(Page.Request["Page"]) + 1).ToString());
}
'lnkNext' 和 'lnkPrevious' 是静态添加和工作的。但“lnkdel_OnClick”不起作用。
我在做什么?
谢谢