Hai
i m trying to load the tabs dynamically.(Using AjaxToolKit). Firstly, when i hit button1 on pageload, it loads tab1() (works good) and when i hit button2, itloads up tab2() All these tabs are ascx pages. In tab1 i m loading WebUserControl.ascx. it works okay.
Issues:
1) When you runthe code, first click on button2, it doesn't load tab2 dynamicaly but it does when u hit button1 for the first time. 2) Repetitive clicking on button1 or button2 should load the same tabs next to eachother again and again but it doesn't 3) Thirdly, the main issue is that I m tryin to load another .ascx on loadtab2() which should have webparts in it. I should be able to load an another custom usercontrol into these web parts dynamically. But i m not able to do so.
Here is my code:
Default.aspx
<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