0
我试图加载标签动态(使用AjaxToolKit)。首先,当我在页面加载命中button1
,它加载tab1
(工作好),当我打button2
,itloads了tab2
无法动态加载标签
所有这些标签是ASCX页。
在tab1
我正在加载WebUserControl.ascx,这工作正常。
问题:
1)当你运行该代码,先点击button2
,它不会加载tab2
dynamicaly但它确实,当你打button1
首次。 2)重复点击button1
或button2
应该一次又一次地加载相同的标签,但它不会。 3)第三,主要问题是,我试着加载另一个.ascx loadtab2
,它应该包含webparts。我应该能够将另一个自定义用户控件加载到这些Web部件中动态地加载。但我无法这样做。
任何人都可以帮助解决这些问题吗?
这里是我的代码:
Default.aspx的
<div>
<asp:AjaxScriptManager ID="AjaxScriptManager1" runat="server">
</asp:AjaxScriptManager>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Show Tab1" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Show Tab2" />
<asp:Button ID="Button3" runat="server" Text="Button" />
</div>
<p>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</p>
Default.aspx.vb
Imports System
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Web.UI.WebControls
Imports System.Collections
Imports System.Collections.Specialized
Imports AjaxControlToolkit
Imports AjaxControlToolkit.ToolkitScriptManager
Public Class _Default
Inherits System.Web.UI.Page
Dim tc1 As New TabContainer()
Dim uc1 As Control
Dim tp1 As New TabPanel()
Dim tp2 As New TabPanel()
Dim tp3 As New TabPanel()
Dim Wp1 As New WebPartManager()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Page.PreRender += new EventHandler(Page_PreRender);
If Session("Tab1") <> Nothing Then
If Session("Tab1").ToString() = "true" Then
LoadTab1()
End If
ElseIf Session("Tab2") <> Nothing Then
If Session("Tab2").ToString() = "true" Then
LoadTab2()
End If
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
If Session("Tab1") Is Nothing Then
Session("Tab1") = "true"
LoadTab1()
ElseIf Session("Tab1").ToString() <> "true" Then
LoadTab1()
End If
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
If Session("Tab2") Is Nothing Then
Session("Tab2") = "true"
LoadTab2()
ElseIf Session("Tab2").ToString() <> "true" Then
LoadTab2()
End If
End Sub
Private Sub LoadTab1()
uc1 = LoadControl("WebUserControl.ascx")
tp1.HeaderText = "Tab1"
'tp2.HeaderText = "Tab2"
tp1.Controls.Add(uc1)
tc1.Tabs.Add(tp1)
'tc1.Tabs.Add(tp2)
If Session("Tab2") <> Nothing Then
LoadTab2()
End If
'if (Session["Tab2"] == null)
'{
PlaceHolder1.Controls.Add(tc1)
'}
End Sub
Public Sub LoadTab2()
Dim uc2 As UserControl = CType(LoadControl("WebUserControl2.ascx"), UserControl)
uc2.ID = "control"
tp2.HeaderText = "Tab2"
tc1.Tabs.Add(tp2)
tp2.controls.add(uc2)
(Error:A Zone can only be added to the Page in or before the Page_Init event...)
End Sub
WebUserControl.ascx.vb
Protected Sub Page_Init()
Dim Btn As New Button()
Btn.ID = "TestButton"
Dim zone1 As New WebPartZone()
zone1.ID = "zone1"
Panel1.Controls.Add(zone1)
' WebPart myWebPart = WebPartManager1.CreateWebPart(Btn);
'myWebPart.ID = "2";
'myWebPart.Title = "MyWebPart";
Dim uc As Control = Me.LoadControl("FeaturedControl.ascx")
uc.ID = "control"
Dim myWebPart As GenericWebPart = WebpartManager1.CreateWebPart(uc)
WebpartManager1.AddWebPart(myWebPart, zone1, 1)
'WebPartManager1.AddWebPart(controol, zone1, 1);
End Sub