473,614 Members | 2,342 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.P age
Dim ini As Org.Mentalis.Fi les.IniReader, dirname As String
Dim nxtBtn As Button, prevBtn As Button
Protected WithEvents cmdPrev As System.Web.UI.W ebControls.Butt on
Protected WithEvents cmdNext As System.Web.UI.W ebControls.Butt on
Protected WithEvents plh As System.Web.UI.W ebControls.Plac eHolder
'Added by hand
Protected Form1 As System.Web.UI.H tmlControls.Htm lForm
Protected WithEvents cCheck As System.Web.UI.W ebControls.Chec kBoxList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) 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.H tmlControls.Htm lTable
Dim row As System.Web.UI.H tmlControls.Htm lTableRow = New HtmlTableRow
Dim btnRow As System.Web.UI.H tmlControls.Htm lTableRow = 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.Nam e = "Verdana"
cCheck.Font.Siz e = FontUnit.Parse( 12)
cCheck.Font.Bol d = True
nxtBtn = New Button
nxtBtn.ID = "cmdNext"
nxtBtn.Text = "Next"
nxtBtn.CommandN ame = "next"
prevBtn = New Button
prevBtn.Text = "Previous"
prevBtn.Command Name = "prev"
prevBtn.ID = "cmdPreviou s"
aPath = Request.ServerV ariables("PATH_ TRANSLATED")
aPath = Left(aPath, InStrRev(aPath, "\"))
examTitle = Session("ExamTi tle")
usrName = Session("userNa me")
'strLoad="windo w.opener.close( )"
Session.Content s.RemoveAll()
'************** *************** ************
'For Testing locally on my system
'Session("Title ")=Request.FORM ("subname")
'************** *************** **************
'Actual code
'Session("Title ")=examTitl e
Session("Title" ) = "IIT"
Session("begin" ) = 0
Session("result page") = "result1.as px"
Session("userid ") = usrName
'************** *************** ************
Dim fileEntries As String() = System.IO.Direc tory.GetFiles(a Path & Session("Title" ))
If System.IO.Direc tory.Exists(aPa th & Session("Title" )) = False Then
Response.Redire ct("Error.aspx" )
End If
For Each fileName In fileEntries
ini = New Org.Mentalis.Fi les.IniReader(f ileName)
Exit For
Next fileName
Session("SHOW_E NT") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_ENT")
Session("SHOW_M OD") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_MOD")
Session("SHOW_S UB") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_SUB")
Session("SHOW_S TO") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_STO")
Session("SHOW_I NS") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_INS")
Session("SHOW_P FM") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_PFM")
Session("SHOW_U SR") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_USR")
cnt = 0
If Session("SHOW_S UB") = 1 Then
strsub0 = ini.ReadString( "SUBJECTS", "SUB0", "SS")
commaPos = InStr(1, strsub0, ",", CompareMethod.B inary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Ad d(New ListItem(subnam e, "sub" & cnt))
strsub0 = ini.ReadString( "SUBJECTS", "SUB1", "SS")
cnt = cnt + 1
Do While strsub0 <> "SS"
commaPos = InStr(1, strsub0, ",", CompareMethod.B inary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Ad d(New ListItem(subnam e, "sub" & cnt))
cnt = cnt + 1
strsub0 = ini.ReadString( "SUBJECTS", "SUB" & cnt, "SS")
Loop
End If
Session("begin" ) = Session("begin" ) + 1
'cmdPrev.Enable d = False
cell2.InnerText = "Avaliable Subjects"
cell.Align = "left"
cell2.Controls. Add(cCheck)
'row.Cells.Add( cell)
btncell1.Contro ls.Add(prevBtn)
btncell2.Contro ls.Add(nxtBtn)
row.Cells.Add(c ell2)
btnRow.Cells.Ad d(btncell1)
btnRow.Cells.Ad d(btncell2)
cTable.Rows.Add (row)
'cTable.Rows.Ad d(btnRow)
plh.Controls.Ad d(cTable)
'AddHandler nxtBtn.Click, AddressOf nxtbtn_click
End If
End Sub
Private Sub cmdNext_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles cmdNext.Click
Response.Write( "Hi You have Clicked Me")
'Error Coming at this line
Response.Write( cCheck.Selected Item.Text)
End Sub

End Class
Nov 18 '05 #1
4 1594
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.P age
Dim ini As Org.Mentalis.Fi les.IniReader, dirname As String
Dim nxtBtn As Button, prevBtn As Button
Protected WithEvents cmdPrev As System.Web.UI.W ebControls.Butt on
Protected WithEvents cmdNext As System.Web.UI.W ebControls.Butt on
Protected WithEvents plh As System.Web.UI.W ebControls.Plac eHolder
'Added by hand
Protected Form1 As System.Web.UI.H tmlControls.Htm lForm
Protected WithEvents cCheck As System.Web.UI.W ebControls.Chec kBoxList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.H tmlControls.Htm lTable
Dim row As System.Web.UI.H tmlControls.Htm lTableRow = New HtmlTableRow
Dim btnRow As System.Web.UI.H tmlControls.Htm lTableRow = 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.Nam e = "Verdana"
cCheck.Font.Siz e = FontUnit.Parse( 12)
cCheck.Font.Bol d = True
nxtBtn = New Button
nxtBtn.ID = "cmdNext"
nxtBtn.Text = "Next"
nxtBtn.CommandN ame = "next"
prevBtn = New Button
prevBtn.Text = "Previous"
prevBtn.Command Name = "prev"
prevBtn.ID = "cmdPreviou s"
aPath = Request.ServerV ariables("PATH_ TRANSLATED")
aPath = Left(aPath, InStrRev(aPath, "\"))
examTitle = Session("ExamTi tle")
usrName = Session("userNa me")
'strLoad="windo w.opener.close( )"
Session.Content s.RemoveAll()
'************** *************** ************
'For Testing locally on my system
'Session("Title ")=Request.FORM ("subname")
'************** *************** **************
'Actual code
'Session("Title ")=examTitl e
Session("Title" ) = "IIT"
Session("begin" ) = 0
Session("result page") = "result1.as px"
Session("userid ") = usrName
'************** *************** ************
Dim fileEntries As String() = System.IO.Direc tory.GetFiles(a Path &
Session("Title" ))
If System.IO.Direc tory.Exists(aPa th & Session("Title" )) = False Then
Response.Redire ct("Error.aspx" )
End If
For Each fileName In fileEntries
ini = New Org.Mentalis.Fi les.IniReader(f ileName)
Exit For
Next fileName
Session("SHOW_E NT") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_ENT")
Session("SHOW_M OD") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_MOD")
Session("SHOW_S UB") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_SUB")
Session("SHOW_S TO") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_STO")
Session("SHOW_I NS") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_INS")
Session("SHOW_P FM") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_PFM")
Session("SHOW_U SR") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_USR")
cnt = 0
If Session("SHOW_S UB") = 1 Then
strsub0 = ini.ReadString( "SUBJECTS", "SUB0", "SS")
commaPos = InStr(1, strsub0, ",", CompareMethod.B inary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Ad d(New ListItem(subnam e, "sub" & cnt))
strsub0 = ini.ReadString( "SUBJECTS", "SUB1", "SS")
cnt = cnt + 1
Do While strsub0 <> "SS"
commaPos = InStr(1, strsub0, ",", CompareMethod.B inary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Ad d(New ListItem(subnam e, "sub" & cnt))
cnt = cnt + 1
strsub0 = ini.ReadString( "SUBJECTS", "SUB" & cnt, "SS")
Loop
End If
Session("begin" ) = Session("begin" ) + 1
'cmdPrev.Enable d = False
cell2.InnerText = "Avaliable Subjects"
cell.Align = "left"
cell2.Controls. Add(cCheck)
'row.Cells.Add( cell)
btncell1.Contro ls.Add(prevBtn)
btncell2.Contro ls.Add(nxtBtn)
row.Cells.Add(c ell2)
btnRow.Cells.Ad d(btncell1)
btnRow.Cells.Ad d(btncell2)
cTable.Rows.Add (row)
'cTable.Rows.Ad d(btnRow)
plh.Controls.Ad d(cTable)
'AddHandler nxtBtn.Click, AddressOf nxtbtn_click
End If
End Sub
Private Sub cmdNext_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles cmdNext.Click
Response.Write( "Hi You have Clicked Me")
*'Error Coming at this line*
*Response.Write (cCheck.Selecte dItem.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******** ******@tk2msftn gp13.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.P age
Dim ini As Org.Mentalis.Fi les.IniReader, dirname As String
Dim nxtBtn As Button, prevBtn As Button
Protected WithEvents cmdPrev As System.Web.UI.W ebControls.Butt on
Protected WithEvents cmdNext As System.Web.UI.W ebControls.Butt on
Protected WithEvents plh As System.Web.UI.W ebControls.Plac eHolder
'Added by hand
Protected Form1 As System.Web.UI.H tmlControls.Htm lForm
Protected WithEvents cCheck As System.Web.UI.W ebControls.Chec kBoxList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.H tmlControls.Htm lTable
Dim row As System.Web.UI.H tmlControls.Htm lTableRow = New HtmlTableRow
Dim btnRow As System.Web.UI.H tmlControls.Htm lTableRow = 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.Nam e = "Verdana"
cCheck.Font.Siz e = FontUnit.Parse( 12)
cCheck.Font.Bol d = True
nxtBtn = New Button
nxtBtn.ID = "cmdNext"
nxtBtn.Text = "Next"
nxtBtn.CommandN ame = "next"
prevBtn = New Button
prevBtn.Text = "Previous"
prevBtn.Command Name = "prev"
prevBtn.ID = "cmdPreviou s"
aPath = Request.ServerV ariables("PATH_ TRANSLATED")
aPath = Left(aPath, InStrRev(aPath, "\"))
examTitle = Session("ExamTi tle")
usrName = Session("userNa me")
'strLoad="windo w.opener.close( )"
Session.Content s.RemoveAll()
'************** *************** ************
'For Testing locally on my system
'Session("Title ")=Request.FORM ("subname")
'************** *************** **************
'Actual code
'Session("Title ")=examTitl e
Session("Title" ) = "IIT"
Session("begin" ) = 0
Session("result page") = "result1.as px"
Session("userid ") = usrName
'************** *************** ************
Dim fileEntries As String() = System.IO.Direc tory.GetFiles(a Path &
Session("Title" ))
If System.IO.Direc tory.Exists(aPa th & Session("Title" )) = False Then
Response.Redire ct("Error.aspx" )
End If
For Each fileName In fileEntries
ini = New Org.Mentalis.Fi les.IniReader(f ileName)
Exit For
Next fileName
Session("SHOW_E NT") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_ENT")
Session("SHOW_M OD") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_MOD")
Session("SHOW_S UB") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_SUB")
Session("SHOW_S TO") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_STO")
Session("SHOW_I NS") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_INS")
Session("SHOW_P FM") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_PFM")
Session("SHOW_U SR") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_USR")
cnt = 0
If Session("SHOW_S UB") = 1 Then
strsub0 = ini.ReadString( "SUBJECTS", "SUB0", "SS")
commaPos = InStr(1, strsub0, ",", CompareMethod.B inary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Ad d(New ListItem(subnam e, "sub" & cnt))
strsub0 = ini.ReadString( "SUBJECTS", "SUB1", "SS")
cnt = cnt + 1
Do While strsub0 <> "SS"
commaPos = InStr(1, strsub0, ",", CompareMethod.B inary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Ad d(New ListItem(subnam e, "sub" & cnt))
cnt = cnt + 1
strsub0 = ini.ReadString( "SUBJECTS", "SUB" & cnt, "SS")
Loop
End If
Session("begin" ) = Session("begin" ) + 1
'cmdPrev.Enable d = False
cell2.InnerText = "Avaliable Subjects"
cell.Align = "left"
cell2.Controls. Add(cCheck)
'row.Cells.Add( cell)
btncell1.Contro ls.Add(prevBtn)
btncell2.Contro ls.Add(nxtBtn)
row.Cells.Add(c ell2)
btnRow.Cells.Ad d(btncell1)
btnRow.Cells.Ad d(btncell2)
cTable.Rows.Add (row)
'cTable.Rows.Ad d(btnRow)
plh.Controls.Ad d(cTable)
'AddHandler nxtBtn.Click, AddressOf nxtbtn_click
End If
End Sub
Private Sub cmdNext_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles cmdNext.Click
Response.Write( "Hi You have Clicked Me")
'Error Coming at this line
Response.Write( cCheck.Selected Item.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.supe rnews.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.P age
Dim ini As Org.Mentalis.Fi les.IniReader, dirname As String
Dim nxtBtn As Button, prevBtn As Button
Protected WithEvents cmdPrev As System.Web.UI.W ebControls.Butt on
Protected WithEvents cmdNext As System.Web.UI.W ebControls.Butt on
Protected WithEvents plh As System.Web.UI.W ebControls.Plac eHolder
'Added by hand
Protected Form1 As System.Web.UI.H tmlControls.Htm lForm
Protected WithEvents cCheck As System.Web.UI.W ebControls.Chec kBoxList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent() End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.H tmlControls.Htm lTable
Dim row As System.Web.UI.H tmlControls.Htm lTableRow = New HtmlTableRow
Dim btnRow As System.Web.UI.H tmlControls.Htm lTableRow = 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.Nam e = "Verdana"
cCheck.Font.Siz e = FontUnit.Parse( 12)
cCheck.Font.Bol d = True
nxtBtn = New Button
nxtBtn.ID = "cmdNext"
nxtBtn.Text = "Next"
nxtBtn.CommandN ame = "next"
prevBtn = New Button
prevBtn.Text = "Previous"
prevBtn.Command Name = "prev"
prevBtn.ID = "cmdPreviou s"
aPath = Request.ServerV ariables("PATH_ TRANSLATED")
aPath = Left(aPath, InStrRev(aPath, "\"))
examTitle = Session("ExamTi tle")
usrName = Session("userNa me")
'strLoad="windo w.opener.close( )"
Session.Content s.RemoveAll()
'************** *************** ************
'For Testing locally on my system
'Session("Title ")=Request.FORM ("subname")
'************** *************** **************
'Actual code
'Session("Title ")=examTitl e
Session("Title" ) = "IIT"
Session("begin" ) = 0
Session("result page") = "result1.as px"
Session("userid ") = usrName
'************** *************** ************
Dim fileEntries As String() = System.IO.Direc tory.GetFiles(a Path &
Session("Title" ))
If System.IO.Direc tory.Exists(aPa th & Session("Title" )) = False Then
Response.Redire ct("Error.aspx" )
End If
For Each fileName In fileEntries
ini = New Org.Mentalis.Fi les.IniReader(f ileName)
Exit For
Next fileName
Session("SHOW_E NT") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_ENT")
Session("SHOW_M OD") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_MOD")
Session("SHOW_S UB") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_SUB")
Session("SHOW_S TO") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_STO")
Session("SHOW_I NS") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_INS")
Session("SHOW_P FM") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_PFM")
Session("SHOW_U SR") = ini.ReadString( "USAGE_CONFIGUR ATION", "SHOW_USR")
cnt = 0
If Session("SHOW_S UB") = 1 Then
strsub0 = ini.ReadString( "SUBJECTS", "SUB0", "SS")
commaPos = InStr(1, strsub0, ",", CompareMethod.B inary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Ad d(New ListItem(subnam e, "sub" & cnt))
strsub0 = ini.ReadString( "SUBJECTS", "SUB1", "SS")
cnt = cnt + 1
Do While strsub0 <> "SS"
commaPos = InStr(1, strsub0, ",", CompareMethod.B inary)
subname = Mid(strsub0, 1, commaPos - 1)
cCheck.Items.Ad d(New ListItem(subnam e, "sub" & cnt))
cnt = cnt + 1
strsub0 = ini.ReadString( "SUBJECTS", "SUB" & cnt, "SS")
Loop
End If
Session("begin" ) = Session("begin" ) + 1
'cmdPrev.Enable d = False
cell2.InnerText = "Avaliable Subjects"
cell.Align = "left"
cell2.Controls. Add(cCheck)
'row.Cells.Add( cell)
btncell1.Contro ls.Add(prevBtn)
btncell2.Contro ls.Add(nxtBtn)
row.Cells.Add(c ell2)
btnRow.Cells.Ad d(btncell1)
btnRow.Cells.Ad d(btncell2)
cTable.Rows.Add (row)
'cTable.Rows.Ad d(btnRow)
plh.Controls.Ad d(cTable)
'AddHandler nxtBtn.Click, AddressOf nxtbtn_click
End If
End Sub
Private Sub cmdNext_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles cmdNext.Click
Response.Write( "Hi You have Clicked Me")
*'Error Coming at this line*
*Response.Write (cCheck.Selecte dItem.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
5470
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 dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
0
2465
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 added row it also removes the row at the end along with the added row. Plz tell me if, I am missing any thing. Code </asp:datagrid>
8
4309
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 button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
9
7033
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 to VB, plus the address bar would show something like this: www.somethinghere?id=3 and if you change number 3 from the address bar to (for example) 34 or 71 you would get different page with the same formatting like I.e: www.somethinghere?id=34...
3
5480
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 following error when the DDL is added (but not the Label): "Control 'ctl07' of type 'DropDownList' must be placed inside a form tag
6
11067
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 how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
9
7920
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 contains a placeholder and I add the control to it, the user control is a formview bound to an object datsource. This works great until I post back the page and the user control disappears. What am I doing wrong? Regards, Chris. Protected Sub...
4
4472
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 selected, the row is added using JavaScript. The script uses cloneNode to clone a hidden template row and all of its children and then adds the new row to the table, updates all of the child control Ids and sets visibility etc. The hidden...
7
6191
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 something. The buttons show up and post back, but the events do not fire. any help would be appreciated!!! Thank you. protected void gvEntitiesRowDataBound(object sender, GridViewRowEventArgs e) {
1
4888
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 set text boxes and labels inside the table rows. I then added a button. All of these are done through code. The problem that i am having is i can get the value from a text box with resides inside the first panel (out side of panel that is...
0
8197
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8640
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8589
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7114
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6093
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2573
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 we have to send another system
1
1757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.