动态添加tabstrip和multipageview

时间:2016-06-23 09:40:21

标签: asp.net vb.net telerik

我有下面的代码,它添加标签和网页浏览很好。但是在2个标签后它将不再添加并继续抱怨radeditor2已经存在。 我知道我没有添加相同的ID。而且不知道为什么它一直试图添加以前的标签而不是新标签。所以说我用radedtor1添加tab1。然后tab2与radeditor2。一切正常当我尝试使用radeditor3添加tab3时,它不会让我抱怨radeditor2已经存在。我注意到的一件事是,每次创建选项卡时都会触发RadMultiPage1_PageViewCreated。如果你创建了1,那么它将会触及该方法1次,2将会触及2次,依此类推。

所以请帮我解决这个问题。非常感谢你的时间

<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

1 个答案:

答案 0 :(得分:0)

一个小小的错误可能会让你付出沉重的代价。我想出了我的问题,我将在这里发布,以防有​​人犯了与我一样的愚蠢错误。谢谢大家的时间

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