我正在尝试为LinkButton控件动态设置PostBackTrigger,该控件位于向导的FinishNavigationTemplate内的占位符控件内。我想做一个正常回发的原因是因为按钮开始下载。
我的(简化)标记看起来像这样:
<asp:UpdatePanel runat="server" id="updPanel">
<ContentTemplate>
<asp:Wizard runat="server" ID="wizard">
<WizardSteps>
<asp:WizardStep runat="server" Title="Step 1">
Step data
</asp:WizardStep>
</WizardSteps>
<FinishNavigationTemplate>
<asp:Placeholder ID="phTest" Visible="false" runat="server">
<asp:LinkButton id="lbtnClick" runat="server" />
</asp:Placeholder>
</FinishNavigationTemplate>
</asp:Wizard>
</ContentTemplate>
</asp:UpdatePanel>
现在,一旦PlaceHolder Visible属性设置为true,我就不会将Linkbutton id添加为PostBackTrigger。
protected void Page_Load(object sender, System.EventArgs e)
{
PlaceHolder phTest = wizard.FindControl("FinishNavigationTemplateContainerID$phTest") as PlaceHolder;
phTest.Visible = true;
LinkButton lbtnClick = offerWizard.FindControl("FinishNavigationTemplateContainerID$lbtnClick") as LinkButton;
PostBackTrigger trigger = new PostBackTrigger();
trigger.ControlID = lbtnClick.ID;
//trigger.ControlID = lbtnClick.ClientID;
//trigger.ControlID = "FinishNavigationTemplateContainerID$lbtnClick";
updPanel.Triggers.Add(trigger);
}
这给了我一个例外“在UpdatePanel'nitPanel'中找不到触发器ID为lbtnClick'的触发器。” 有没有办法保持标记的方式,并以某种方式让linkbutton做正常的回发?
答案 0 :(得分:1)
您还可以使用trigger.ControlID = lbtnClick.UniqueID;
答案 1 :(得分:0)
这似乎有效,但如果有人有更好的解决方案,我会很乐意接受它
PostBackTrigger trigger = new PostBackTrigger();
trigger.ControlID = "offerWizard$FinishNavigationTemplateContainerID$lbtnClick";
updPanel.Triggers.Add(trigger);