i have PlaceHolder in which i loads runtime some usercontrols.
<asp:UpdatePanel ID="UpdatePanel_Items" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder_Main" runat="server"></asp:PlaceHolder>
</ContentTemplate>
user control has element
<asp:LinkButton ID="LinkButton_AddToCart" runat="server" OnClick="LinkButton_AddToCart_Click" CausesValidation="false"></asp:LinkButton>
After adding user controls to placeholder, i need to add postback 开发者_如何转开发trigger for LinkButton_AddToCart in every user control . i tried this:
foreach (Control item in PlaceHolder_Main.Controls)
{
try
{
WUC_Rim wuc = (WUC_Rim)item;
PostBackTrigger trigger = new PostBackTrigger();
LinkButton lnk = wuc.GetLinkButton_AddToCart();
trigger.ControlID = lnk.UniqueID;
UpdatePanel_Items.Triggers.Add(trigger);
}
catch
{
}
}
but has an error
A control with ID 'ctl00$MainContent$ctl02$LinkButton_AddToCart' could not be found for the trigger in UpdatePanel 'UpdatePanel_Items'.
PostBack triggers should be registered directly with ScriptManager, try it like this:
ScriptManager.GetCurrent(this).RegisterPostBackControl(wuc.GetLinkButton_AddToCart());
(Of course if this code is not in your Page class, you must put reference to it instead of 'this')
Use this:
import postback url as same page
<asp:ImageButton AlternateText='<%#Eval("JobLink") %>' runat="server" ID="ibtnExcel"
ImageUrl="~/images/excel-doc.PNG" Width="25" Height="25" Visible='<%#Eval("Visible") %>'
ToolTip="Export to excel sheet" OnClick="ExportToExcel" PostBackUrl="~/billing/BillingHome.aspx" />
精彩评论