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