2016-06-23 54 views
0

我有下面的代碼,它增加了標籤和pageview罰款。但在2標籤之後,它不會再添加,並不斷抱怨radeditor2已經存在。 我知道我沒有添加相同的ID。不知道爲什麼它會一直嘗試添加前一個標籤而不是新標籤。所以說,我添加tab1與radedtor1。然後tab2與radeditor2。所有罰款當我嘗試添加raderitor3 tab3,它不會讓我抱怨radeditor2已經存在。我注意到的一件事是RadMultiPage1_PageViewCreated在每次創建選項卡時都會被觸發。如果你創建了1,它將會按照該方法1次,2次將會2次,等等。動態添加tabstrip和multipageview

所以請幫我解決這個問題。非常感謝你的時間

<script type="text/javascript"> 
    function OnClientTabSelecting(sender, eventArgs) { 
     var tab = eventArgs.get_tab(); 
     if (tab.get_text() == "") 
     { 
      document.getElementById("div_AddTab").style.display = "block"; 
      eventArgs.set_cancel(true); 
     } 
     else 
     { 
      eventArgs.set_cancel(false); 
     } 
    } 
</script> 
<div id="div_AddTab" style="display:none;"> 
    Tab Title: <telerik:RadTextBox ID="txt_TabTitle" runat="server" /> 
    Element Type: <telerik:RadComboBox ID="ddl_ElementType" runat="server" /> 
    <telerik:RadButton ID="btn_AddTab" runat="server" Text="Add Tab" /> 
</div> 
<div> 
    <telerik:RadTabStrip RenderMode="Lightweight" runat="server" ID="RadTabStrip1" Orientation="HorizontalTop" Width="760" 
     MultiPageID="RadMultiPage1" Skin="Windows7" OnClientTabSelecting="OnClientTabSelecting"> 
     <Tabs> 
      <telerik:RadTab runat="server" Text="tab1" /> 
      <telerik:RadTab runat="server" Text="tab2" /> 
      <telerik:RadTab runat="server" Text="" ImageUrl="~/images/add.png" /> 
     </Tabs> 
    </telerik:RadTabStrip> 
    <telerik:RadMultiPage ID="RadMultiPage1" runat="server" Width="760" Height="380" SelectedIndex="0" OnPageViewCreated="RadMultiPage1_PageViewCreated"> 
     <telerik:RadPageView ID="RadPageView1" runat="server"> 
      test 
     </telerik:RadPageView> 
     <telerik:RadPageView ID="RadPageView2" runat="server"> 
      test 2 
     </telerik:RadPageView>    
    </telerik:RadMultiPage> 
</div> 


Protected Sub btn_AddTab_Click(sender As Object, e As EventArgs) Handles btn_AddTab.Click   
    AddPageView(Trim(txt_TabTitle.Text), ddl_ElementType.SelectedItem.Text) 
    AddTab(Trim(txt_TabTitle.Text)) 
End Sub 

Protected Sub RadMultiPage1_PageViewCreated(sender As Object, e As RadMultiPageEventArgs) 
    Dim rad_Editor As RadEditor = New RadEditor 
    Dim radSlider As New RadSlider 
    Select Case ddl_ElementType.SelectedValue 
     Case "T" 
      rad_Editor.ID = "radEditor_" & Trim(txt_TabTitle.Text) 
      e.PageView.Controls.Add(rad_Editor) 
     Case "B" 

     Case "N" 
    End Select 
End Sub 

Private Sub AddTab(title As String) 
    Dim tabTemplate = New TabTemplate() 
    Dim tab As New RadTab() With { _ 
     .Text = title, 
     .PageViewID = "pv_" & title _ 
    } 
    RadTabStrip1.Tabs.Insert((RadTabStrip1.Tabs.Count - 1), tab) 
    RadTabStrip1.DataBind() 
    RadTabStrip1.SelectedIndex = tab.Index 
End Sub 

Private Sub AddPageView(pvId As String, elementType As String) 
    Dim pageView As RadPageView = New RadPageView() 
    pageView.ID = "pv_" & pvId 
    pageView.CssClass = "pageView" 
    RadMultiPage1.PageViews.Add(pageView) 
    RadMultiPage1.SelectedIndex = pageView.Index 

End Sub 

回答

0

一個小錯誤可能會讓你付出沉重的代價。我想出了我的問題,我會在這裏發佈它,以防某人犯了與我一樣的愚蠢錯誤。感謝大家的時間

,而不是rad_Editor.ID = "radEditor_" & Trim(txt_TabTitle.Text) 使用rad_Editor.ID = "radEditor_" & e.PageView.ID