473,498 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically Adding Controls

Hi

I am doing one thing in my website ,actually i want to add controls dynamically to a web form and want to access the
elements but when i postback the form,and access that control, it gives error Object reference not set to an instance of an object.
************************************************** **********************
************************************************** ************************
Public Class index2
Inherits System.Web.UI.Page
Dim ini As Org.Mentalis.Files.IniReader, dirname As String
Dim nxtBtn As Button, prevBtn As Button
Protected WithEvents cmdPrev As System.Web.UI.WebControls.Button
Protected WithEvents cmdNext As System.Web.UI.WebControls.Button
Protected WithEvents plh As System.Web.UI.WebControls.PlaceHolder
'Added by hand
Protected Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents cCheck As System.Web.UI.WebControls.CheckBoxList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack = False Then
Dim aPath As String, temp As String, strsub0 As String, cnt As Integer
Dim commaPos As Integer, examTitle As String, usrName As String
Dim fileName As String, subname As String, cCheck As CheckBoxList
Dim cTable As New System.Web.UI.HtmlControls.HtmlTable
Dim row As System.Web.UI.HtmlControls.HtmlTableRow = New HtmlTableRow
Dim btnRow As System.Web.UI.HtmlControls.HtmlTableRow = New HtmlTableRow
Dim cell As HtmlTableCell = New HtmlTableCell
Dim cell2 As HtmlTableCell = New HtmlTableCell
Dim btncell1 As HtmlTableCell = New HtmlTableCell
Dim btncell2 As HtmlTableCell = New HtmlTableCell
cCheck = New CheckBoxList
cCheck.ID = "subname"
cCheck.Font.Name = "Verdana"
cCheck.Font.Size = FontUnit.Parse(12)
cCheck.Font.Bold = True
nxtBtn = New Button
nxtBtn.ID = "cmdNext"
nxtBtn.Text = "Next"
nxtBtn.CommandName = "next"
prevBtn = New Button
prevBtn.Text = "Previous"
prevBtn.CommandName = "prev"
prevBtn.ID = "cmdPrevious"
aPath = Request.ServerVariables("PATH_TRANSLATED")
aPath = Left(aPath, InStrRev(aPath, "\"))
examTitle = Session("ExamTitle")
usrName = Session("userName")
'strLoad="window.opener.close()"
Session.Contents.RemoveAll()
'*****************************************
'For Testing locally on my system
'Session("Title")=Request.FORM("subname")
'*******************************************
'Actual code
'Session("Title")=examTitle
Session("Title") = "IIT"
Session("begin") = 0
Session("resultpage") = "result1.aspx"
Session("userid") = usrName
'*****************************************
Dim fileEntries As String() = System.IO.Directory.GetFiles(aPath & Session("Title"))
If System.IO.Directory.Exists(aPath & Session("Title")) = False Then
Response.Redirect("Error.aspx")
End If
For Each fileName In fileEntries
ini = New Org.Mentalis.Files.IniReader(fileName)
Exit For
Next fileName
Session("SHOW_ENT") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_ENT")
Session("SHOW_MOD") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_MOD")
Session("SHOW_SUB") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_SUB")
Session("SHOW_STO") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_STO")
Session("SHOW_INS") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_INS")
Session("SHOW_PFM") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_PFM")
Session("SHOW_USR") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_USR")
cnt = 0
If Session("SHOW_SUB") = 1 Then
strsub0 = ini.ReadString("SUBJECTS", "SUB0", "SS")
commaPos = InStr(1, strsub0, ",", CompareMethod.Binary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Add(New ListItem(subname, "sub" & cnt))
strsub0 = ini.ReadString("SUBJECTS", "SUB1", "SS")
cnt = cnt + 1
Do While strsub0 <> "SS"
commaPos = InStr(1, strsub0, ",", CompareMethod.Binary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Add(New ListItem(subname, "sub" & cnt))
cnt = cnt + 1
strsub0 = ini.ReadString("SUBJECTS", "SUB" & cnt, "SS")
Loop
End If
Session("begin") = Session("begin") + 1
'cmdPrev.Enabled = False
cell2.InnerText = "Avaliable Subjects"
cell.Align = "left"
cell2.Controls.Add(cCheck)
'row.Cells.Add(cell)
btncell1.Controls.Add(prevBtn)
btncell2.Controls.Add(nxtBtn)
row.Cells.Add(cell2)
btnRow.Cells.Add(btncell1)
btnRow.Cells.Add(btncell2)
cTable.Rows.Add(row)
'cTable.Rows.Add(btnRow)
plh.Controls.Add(cTable)
'AddHandler nxtBtn.Click, AddressOf nxtbtn_click
End If
End Sub
Private Sub cmdNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdNext.Click
Response.Write("Hi You have Clicked Me")
'Error Coming at this line
Response.Write(cCheck.SelectedItem.Text)
End Sub

End Class
Nov 18 '05 #1
4 1584
Sandeep wrote:
Hi

I am doing one thing in my website ,actually i want to add controls
dynamically to a web form and want to access the
elements but when i postback the form,and access that control, it gives
error /Object reference not set to an instance of an object./
************************************************** **********************
************************************************** ************************
Public Class index2
Inherits System.Web.UI.Page
Dim ini As Org.Mentalis.Files.IniReader, dirname As String
Dim nxtBtn As Button, prevBtn As Button
Protected WithEvents cmdPrev As System.Web.UI.WebControls.Button
Protected WithEvents cmdNext As System.Web.UI.WebControls.Button
Protected WithEvents plh As System.Web.UI.WebControls.PlaceHolder
'Added by hand
Protected Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents cCheck As System.Web.UI.WebControls.CheckBoxList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack = False Then
Dim aPath As String, temp As String, strsub0 As String, cnt As Integer
Dim commaPos As Integer, examTitle As String, usrName As String
Dim fileName As String, subname As String, cCheck As CheckBoxList
Dim cTable As New System.Web.UI.HtmlControls.HtmlTable
Dim row As System.Web.UI.HtmlControls.HtmlTableRow = New HtmlTableRow
Dim btnRow As System.Web.UI.HtmlControls.HtmlTableRow = New HtmlTableRow
Dim cell As HtmlTableCell = New HtmlTableCell
Dim cell2 As HtmlTableCell = New HtmlTableCell
Dim btncell1 As HtmlTableCell = New HtmlTableCell
Dim btncell2 As HtmlTableCell = New HtmlTableCell
cCheck = New CheckBoxList
cCheck.ID = "subname"
cCheck.Font.Name = "Verdana"
cCheck.Font.Size = FontUnit.Parse(12)
cCheck.Font.Bold = True
nxtBtn = New Button
nxtBtn.ID = "cmdNext"
nxtBtn.Text = "Next"
nxtBtn.CommandName = "next"
prevBtn = New Button
prevBtn.Text = "Previous"
prevBtn.CommandName = "prev"
prevBtn.ID = "cmdPrevious"
aPath = Request.ServerVariables("PATH_TRANSLATED")
aPath = Left(aPath, InStrRev(aPath, "\"))
examTitle = Session("ExamTitle")
usrName = Session("userName")
'strLoad="window.opener.close()"
Session.Contents.RemoveAll()
'*****************************************
'For Testing locally on my system
'Session("Title")=Request.FORM("subname")
'*******************************************
'Actual code
'Session("Title")=examTitle
Session("Title") = "IIT"
Session("begin") = 0
Session("resultpage") = "result1.aspx"
Session("userid") = usrName
'*****************************************
Dim fileEntries As String() = System.IO.Directory.GetFiles(aPath &
Session("Title"))
If System.IO.Directory.Exists(aPath & Session("Title")) = False Then
Response.Redirect("Error.aspx")
End If
For Each fileName In fileEntries
ini = New Org.Mentalis.Files.IniReader(fileName)
Exit For
Next fileName
Session("SHOW_ENT") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_ENT")
Session("SHOW_MOD") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_MOD")
Session("SHOW_SUB") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_SUB")
Session("SHOW_STO") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_STO")
Session("SHOW_INS") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_INS")
Session("SHOW_PFM") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_PFM")
Session("SHOW_USR") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_USR")
cnt = 0
If Session("SHOW_SUB") = 1 Then
strsub0 = ini.ReadString("SUBJECTS", "SUB0", "SS")
commaPos = InStr(1, strsub0, ",", CompareMethod.Binary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Add(New ListItem(subname, "sub" & cnt))
strsub0 = ini.ReadString("SUBJECTS", "SUB1", "SS")
cnt = cnt + 1
Do While strsub0 <> "SS"
commaPos = InStr(1, strsub0, ",", CompareMethod.Binary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Add(New ListItem(subname, "sub" & cnt))
cnt = cnt + 1
strsub0 = ini.ReadString("SUBJECTS", "SUB" & cnt, "SS")
Loop
End If
Session("begin") = Session("begin") + 1
'cmdPrev.Enabled = False
cell2.InnerText = "Avaliable Subjects"
cell.Align = "left"
cell2.Controls.Add(cCheck)
'row.Cells.Add(cell)
btncell1.Controls.Add(prevBtn)
btncell2.Controls.Add(nxtBtn)
row.Cells.Add(cell2)
btnRow.Cells.Add(btncell1)
btnRow.Cells.Add(btncell2)
cTable.Rows.Add(row)
'cTable.Rows.Add(btnRow)
plh.Controls.Add(cTable)
'AddHandler nxtBtn.Click, AddressOf nxtbtn_click
End If
End Sub
Private Sub cmdNext_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdNext.Click
Response.Write("Hi You have Clicked Me")
*'Error Coming at this line*
*Response.Write(cCheck.SelectedItem.Text)*
End Sub

End Class


When you do the postback you need to reinitialize your controls or else
they are empty. There are several different ways you can do this.

#1 if (isPostBack)
#2 go recursive and pass the value in the querystring.
#3 use a session variable.
#4 use the viewstate

Shock
Nov 18 '05 #2
When you add dynamically controls in your page you have to recreate them
every time you visit the page ( no matter it is postback or not ). Take a
look at this article of Microsoft , that describes how to add controls
dynamically

http://support.microsoft.com/default...b;EN-US;317515
Regards
Martin
"Sandeep" <ss***@uptecnet.com> wrote in message
news:#e**************@tk2msftngp13.phx.gbl...
Hi

I am doing one thing in my website ,actually i want to add controls
dynamically to a web form and want to access the
elements but when i postback the form,and access that control, it gives
error Object reference not set to an instance of an object.
************************************************** **********************
************************************************** ************************
Public Class index2
Inherits System.Web.UI.Page
Dim ini As Org.Mentalis.Files.IniReader, dirname As String
Dim nxtBtn As Button, prevBtn As Button
Protected WithEvents cmdPrev As System.Web.UI.WebControls.Button
Protected WithEvents cmdNext As System.Web.UI.WebControls.Button
Protected WithEvents plh As System.Web.UI.WebControls.PlaceHolder
'Added by hand
Protected Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents cCheck As System.Web.UI.WebControls.CheckBoxList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack = False Then
Dim aPath As String, temp As String, strsub0 As String, cnt As Integer
Dim commaPos As Integer, examTitle As String, usrName As String
Dim fileName As String, subname As String, cCheck As CheckBoxList
Dim cTable As New System.Web.UI.HtmlControls.HtmlTable
Dim row As System.Web.UI.HtmlControls.HtmlTableRow = New HtmlTableRow
Dim btnRow As System.Web.UI.HtmlControls.HtmlTableRow = New HtmlTableRow
Dim cell As HtmlTableCell = New HtmlTableCell
Dim cell2 As HtmlTableCell = New HtmlTableCell
Dim btncell1 As HtmlTableCell = New HtmlTableCell
Dim btncell2 As HtmlTableCell = New HtmlTableCell
cCheck = New CheckBoxList
cCheck.ID = "subname"
cCheck.Font.Name = "Verdana"
cCheck.Font.Size = FontUnit.Parse(12)
cCheck.Font.Bold = True
nxtBtn = New Button
nxtBtn.ID = "cmdNext"
nxtBtn.Text = "Next"
nxtBtn.CommandName = "next"
prevBtn = New Button
prevBtn.Text = "Previous"
prevBtn.CommandName = "prev"
prevBtn.ID = "cmdPrevious"
aPath = Request.ServerVariables("PATH_TRANSLATED")
aPath = Left(aPath, InStrRev(aPath, "\"))
examTitle = Session("ExamTitle")
usrName = Session("userName")
'strLoad="window.opener.close()"
Session.Contents.RemoveAll()
'*****************************************
'For Testing locally on my system
'Session("Title")=Request.FORM("subname")
'*******************************************
'Actual code
'Session("Title")=examTitle
Session("Title") = "IIT"
Session("begin") = 0
Session("resultpage") = "result1.aspx"
Session("userid") = usrName
'*****************************************
Dim fileEntries As String() = System.IO.Directory.GetFiles(aPath &
Session("Title"))
If System.IO.Directory.Exists(aPath & Session("Title")) = False Then
Response.Redirect("Error.aspx")
End If
For Each fileName In fileEntries
ini = New Org.Mentalis.Files.IniReader(fileName)
Exit For
Next fileName
Session("SHOW_ENT") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_ENT")
Session("SHOW_MOD") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_MOD")
Session("SHOW_SUB") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_SUB")
Session("SHOW_STO") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_STO")
Session("SHOW_INS") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_INS")
Session("SHOW_PFM") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_PFM")
Session("SHOW_USR") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_USR")
cnt = 0
If Session("SHOW_SUB") = 1 Then
strsub0 = ini.ReadString("SUBJECTS", "SUB0", "SS")
commaPos = InStr(1, strsub0, ",", CompareMethod.Binary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Add(New ListItem(subname, "sub" & cnt))
strsub0 = ini.ReadString("SUBJECTS", "SUB1", "SS")
cnt = cnt + 1
Do While strsub0 <> "SS"
commaPos = InStr(1, strsub0, ",", CompareMethod.Binary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Add(New ListItem(subname, "sub" & cnt))
cnt = cnt + 1
strsub0 = ini.ReadString("SUBJECTS", "SUB" & cnt, "SS")
Loop
End If
Session("begin") = Session("begin") + 1
'cmdPrev.Enabled = False
cell2.InnerText = "Avaliable Subjects"
cell.Align = "left"
cell2.Controls.Add(cCheck)
'row.Cells.Add(cell)
btncell1.Controls.Add(prevBtn)
btncell2.Controls.Add(nxtBtn)
row.Cells.Add(cell2)
btnRow.Cells.Add(btncell1)
btnRow.Cells.Add(btncell2)
cTable.Rows.Add(row)
'cTable.Rows.Add(btnRow)
plh.Controls.Add(cTable)
'AddHandler nxtBtn.Click, AddressOf nxtbtn_click
End If
End Sub
Private Sub cmdNext_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdNext.Click
Response.Write("Hi You have Clicked Me")
'Error Coming at this line
Response.Write(cCheck.SelectedItem.Text)
End Sub

End Class
Nov 18 '05 #3
Can u tell me with exmaple of the methods suggested by u it would be of
great help to me
"Shock" <no@way.com> wrote in message
news:10*************@corp.supernews.com...
Sandeep wrote:
Hi

I am doing one thing in my website ,actually i want to add controls
dynamically to a web form and want to access the
elements but when i postback the form,and access that control, it gives
error /Object reference not set to an instance of an object./
************************************************** **********************
************************************************** ************************ Public Class index2
Inherits System.Web.UI.Page
Dim ini As Org.Mentalis.Files.IniReader, dirname As String
Dim nxtBtn As Button, prevBtn As Button
Protected WithEvents cmdPrev As System.Web.UI.WebControls.Button
Protected WithEvents cmdNext As System.Web.UI.WebControls.Button
Protected WithEvents plh As System.Web.UI.WebControls.PlaceHolder
'Added by hand
Protected Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents cCheck As System.Web.UI.WebControls.CheckBoxList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack = False Then
Dim aPath As String, temp As String, strsub0 As String, cnt As Integer
Dim commaPos As Integer, examTitle As String, usrName As String
Dim fileName As String, subname As String, cCheck As CheckBoxList
Dim cTable As New System.Web.UI.HtmlControls.HtmlTable
Dim row As System.Web.UI.HtmlControls.HtmlTableRow = New HtmlTableRow
Dim btnRow As System.Web.UI.HtmlControls.HtmlTableRow = New HtmlTableRow
Dim cell As HtmlTableCell = New HtmlTableCell
Dim cell2 As HtmlTableCell = New HtmlTableCell
Dim btncell1 As HtmlTableCell = New HtmlTableCell
Dim btncell2 As HtmlTableCell = New HtmlTableCell
cCheck = New CheckBoxList
cCheck.ID = "subname"
cCheck.Font.Name = "Verdana"
cCheck.Font.Size = FontUnit.Parse(12)
cCheck.Font.Bold = True
nxtBtn = New Button
nxtBtn.ID = "cmdNext"
nxtBtn.Text = "Next"
nxtBtn.CommandName = "next"
prevBtn = New Button
prevBtn.Text = "Previous"
prevBtn.CommandName = "prev"
prevBtn.ID = "cmdPrevious"
aPath = Request.ServerVariables("PATH_TRANSLATED")
aPath = Left(aPath, InStrRev(aPath, "\"))
examTitle = Session("ExamTitle")
usrName = Session("userName")
'strLoad="window.opener.close()"
Session.Contents.RemoveAll()
'*****************************************
'For Testing locally on my system
'Session("Title")=Request.FORM("subname")
'*******************************************
'Actual code
'Session("Title")=examTitle
Session("Title") = "IIT"
Session("begin") = 0
Session("resultpage") = "result1.aspx"
Session("userid") = usrName
'*****************************************
Dim fileEntries As String() = System.IO.Directory.GetFiles(aPath &
Session("Title"))
If System.IO.Directory.Exists(aPath & Session("Title")) = False Then
Response.Redirect("Error.aspx")
End If
For Each fileName In fileEntries
ini = New Org.Mentalis.Files.IniReader(fileName)
Exit For
Next fileName
Session("SHOW_ENT") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_ENT")
Session("SHOW_MOD") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_MOD")
Session("SHOW_SUB") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_SUB")
Session("SHOW_STO") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_STO")
Session("SHOW_INS") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_INS")
Session("SHOW_PFM") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_PFM")
Session("SHOW_USR") = ini.ReadString("USAGE_CONFIGURATION", "SHOW_USR")
cnt = 0
If Session("SHOW_SUB") = 1 Then
strsub0 = ini.ReadString("SUBJECTS", "SUB0", "SS")
commaPos = InStr(1, strsub0, ",", CompareMethod.Binary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Add(New ListItem(subname, "sub" & cnt))
strsub0 = ini.ReadString("SUBJECTS", "SUB1", "SS")
cnt = cnt + 1
Do While strsub0 <> "SS"
commaPos = InStr(1, strsub0, ",", CompareMethod.Binary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Add(New ListItem(subname, "sub" & cnt))
cnt = cnt + 1
strsub0 = ini.ReadString("SUBJECTS", "SUB" & cnt, "SS")
Loop
End If
Session("begin") = Session("begin") + 1
'cmdPrev.Enabled = False
cell2.InnerText = "Avaliable Subjects"
cell.Align = "left"
cell2.Controls.Add(cCheck)
'row.Cells.Add(cell)
btncell1.Controls.Add(prevBtn)
btncell2.Controls.Add(nxtBtn)
row.Cells.Add(cell2)
btnRow.Cells.Add(btncell1)
btnRow.Cells.Add(btncell2)
cTable.Rows.Add(row)
'cTable.Rows.Add(btnRow)
plh.Controls.Add(cTable)
'AddHandler nxtBtn.Click, AddressOf nxtbtn_click
End If
End Sub
Private Sub cmdNext_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdNext.Click
Response.Write("Hi You have Clicked Me")
*'Error Coming at this line*
*Response.Write(cCheck.SelectedItem.Text)*
End Sub

End Class


When you do the postback you need to reinitialize your controls or else
they are empty. There are several different ways you can do this.

#1 if (isPostBack)
#2 go recursive and pass the value in the querystring.
#3 use a session variable.
#4 use the viewstate

Shock

Nov 18 '05 #4
As Shock said earlier you just have to reload the controls when the page
loads. The viewstate will automaticly set the controls to the right status
Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5447
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
0
2454
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
8
4296
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
9
7025
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
3
5461
by: Mark Denardo | last post by:
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the...
6
11055
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
9
7901
by: Chris | last post by:
I am dynamically adding a user control to each row in a gridview. The reason I am doing it dynamically is the user control is different depending on certain data in the gridview. The gridview...
4
4449
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
7
6176
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm adding subheadings to a gridview. Each sub head has a few link buttons. I'm adding the controls in the rowdatabound event code follows: sorry about the length here. I have to be missing...
1
4867
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7205
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.