2013-07-19 60 views
0

我想動態地爲一個LinkBut​​ton控件動態地設置一個佔位符控件,該控件位於嚮導的FinishNavigationTemplate內部。我想做普通回發的理由是因爲按鈕開始下載。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> 

現在我wan't添加LinkBut​​ton的ID作爲一次佔位符Visible屬性設置爲true 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); 
} 

這讓我異常「ID爲‘lbtnClick’的控制不能在UpdatePanel的‘updPanel’觸發找到。」 有沒有辦法保持標記的方式,並以某種方式使linkbutton做一個正常的回發?

回答

0

這似乎是工作,但如果有人有更好的解決辦法,我會很樂意接受它

PostBackTrigger trigger = new PostBackTrigger(); 
trigger.ControlID = "offerWizard$FinishNavigationTemplateContainerID$lbtnClick"; 
updPanel.Triggers.Add(trigger); 
1

您還可以使用trigger.ControlID = lbtnClick.UniqueID;