I'm having trouble dynamically adding controls inside an update panel with partial postbacks.I generate some LinkButton dynamically in code behind and set trigger of them, but when I fire them they full postback, even LinkButton Event does not get called when I fire them.They are placed in the 'divPageNumber'
我在使用部分回发动态地在更新面板中添加控件时遇到了麻烦。我在后面的代码中动态生成一些LinkButton并设置它们的触发器,但是当我触发它们时它们完全回发,甚至当我触发它们时也不会调用LinkButton事件。他们被放在'divPageNumber'中
*.aspx:
*的.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>
and *.cs:
和* .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' and 'lnkPrevious' is static added and work. but 'lnkdel_OnClick' doesn't work.
'lnkNext'和'lnkPrevious'是静态添加和工作。但'lnkdel_OnClick'不起作用。
What am I doing?
我在做什么?
thanks
谢谢
1 个解决方案
#1
1
I solve my problem from this thread
我从这个线程解决了我的问题
http://forums.asp.net/t/1895457.aspx/1
http://forums.asp.net/t/1895457.aspx/1
#1
1
I solve my problem from this thread
我从这个线程解决了我的问题
http://forums.asp.net/t/1895457.aspx/1
http://forums.asp.net/t/1895457.aspx/1