473,569 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting item from a Place Holder Error


Hi,

I have a place holder and I have a checkboxlist in it?
why do i get a "System.NullRef erenceException : Object reference not set to
an instance of an object." error why I try to get the selected value from
it?

Thanks,
Stephen

here is what I am doing?
Dim chkBoxList As CheckBoxList

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
ShowCheckBoxes( )
btn_Select.Text = "Display Selected"

End If
End Sub

Private Sub ShowCheckBoxes( )
Dim tString As String = "12px"
chkBoxList = New CheckBoxList
chkBoxList.Item s.Add(New ListItem("Is Enabled", "IsEnabled" ))
chkBoxList.Item s.Add(New ListItem("Is Active", "IsActive") )
chkBoxList.Repe atColumns = 2
chkBoxList.Repe atDirection = RepeatDirection .Horizontal
chkBoxList.Font .Size = FontUnit.Parse( tString)
phCheckButtons. Controls.Add(ch kBoxList)

End Sub
Private Sub btn_Select_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btn_Select.Clic k
If chkBoxList.Sele ctedItem.Text = "Is Enabled" Then
Response.Write( "<script language='javas cript'> { alert('Check Box
Selected.') }</script>")

End If

End Sub
Jun 8 '06 #1
5 1397
Are you making sure that at least one item is checked? If there is no item
checked then the SelectedItem is null and you will have to check for that
being null as well.
"stephen" wrote:

Hi,

I have a place holder and I have a checkboxlist in it?
why do i get a "System.NullRef erenceException : Object reference not set to
an instance of an object." error why I try to get the selected value from
it?

Thanks,
Stephen

here is what I am doing?
Dim chkBoxList As CheckBoxList

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
ShowCheckBoxes( )
btn_Select.Text = "Display Selected"

End If
End Sub

Private Sub ShowCheckBoxes( )
Dim tString As String = "12px"
chkBoxList = New CheckBoxList
chkBoxList.Item s.Add(New ListItem("Is Enabled", "IsEnabled" ))
chkBoxList.Item s.Add(New ListItem("Is Active", "IsActive") )
chkBoxList.Repe atColumns = 2
chkBoxList.Repe atDirection = RepeatDirection .Horizontal
chkBoxList.Font .Size = FontUnit.Parse( tString)
phCheckButtons. Controls.Add(ch kBoxList)

End Sub
Private Sub btn_Select_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btn_Select.Clic k
If chkBoxList.Sele ctedItem.Text = "Is Enabled" Then
Response.Write( "<script language='javas cript'> { alert('Check Box
Selected.') }</script>")

End If

End Sub

Jun 8 '06 #2
Stephen,
anytime you add a control dynamically to an ASP.NET page, if there is a
postback, you must recreate and add the control again, it doesn't
automatically "persist" across page reloads.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"stephen" wrote:

Hi,

I have a place holder and I have a checkboxlist in it?
why do i get a "System.NullRef erenceException : Object reference not set to
an instance of an object." error why I try to get the selected value from
it?

Thanks,
Stephen

here is what I am doing?
Dim chkBoxList As CheckBoxList

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
ShowCheckBoxes( )
btn_Select.Text = "Display Selected"

End If
End Sub

Private Sub ShowCheckBoxes( )
Dim tString As String = "12px"
chkBoxList = New CheckBoxList
chkBoxList.Item s.Add(New ListItem("Is Enabled", "IsEnabled" ))
chkBoxList.Item s.Add(New ListItem("Is Active", "IsActive") )
chkBoxList.Repe atColumns = 2
chkBoxList.Repe atDirection = RepeatDirection .Horizontal
chkBoxList.Font .Size = FontUnit.Parse( tString)
phCheckButtons. Controls.Add(ch kBoxList)

End Sub
Private Sub btn_Select_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btn_Select.Clic k
If chkBoxList.Sele ctedItem.Text = "Is Enabled" Then
Response.Write( "<script language='javas cript'> { alert('Check Box
Selected.') }</script>")

End If

End Sub

Jun 8 '06 #3
Hi Peter and Jeremy,

Thanks for you replies
Actually I did try that option and it did fail,
in my code sample below:
In the click event again i call the "ShowCheckBoxes ()" again
but it still gives me the same error

Thanks,
Stephen

"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in message
news:29******** *************** ***********@mic rosoft.com...
Stephen,
anytime you add a control dynamically to an ASP.NET page, if there is a
postback, you must recreate and add the control again, it doesn't
automatically "persist" across page reloads.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"stephen" wrote:

Hi,

I have a place holder and I have a checkboxlist in it?
why do i get a "System.NullRef erenceException : Object reference not set
to
an instance of an object." error why I try to get the selected value from
it?

Thanks,
Stephen

here is what I am doing?
Dim chkBoxList As CheckBoxList

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
ShowCheckBoxes( )
btn_Select.Text = "Display Selected"

End If
End Sub

Private Sub ShowCheckBoxes( )
Dim tString As String = "12px"
chkBoxList = New CheckBoxList
chkBoxList.Item s.Add(New ListItem("Is Enabled", "IsEnabled" ))
chkBoxList.Item s.Add(New ListItem("Is Active", "IsActive") )
chkBoxList.Repe atColumns = 2
chkBoxList.Repe atDirection = RepeatDirection .Horizontal
chkBoxList.Font .Size = FontUnit.Parse( tString)
phCheckButtons. Controls.Add(ch kBoxList)

End Sub
Private Sub btn_Select_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btn_Select.Clic k
If chkBoxList.Sele ctedItem.Text = "Is Enabled" Then
Response.Write( "<script language='javas cript'> { alert('Check Box
Selected.') }</script>")

End If

End Sub

Jun 9 '06 #4
Move the "ShowCheckBoxes " method call outside of the "If Not IsPostback" block.
What's happening is when you click the button, that is a postback, and since
your ShowCheckboxes call is inside this block, it never recreats the
controls. Sorry, I thought that was clearer than it apparently is.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"stephen" wrote:
Hi Peter and Jeremy,

Thanks for you replies
Actually I did try that option and it did fail,
in my code sample below:
In the click event again i call the "ShowCheckBoxes ()" again
but it still gives me the same error

Thanks,
Stephen

"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in message
news:29******** *************** ***********@mic rosoft.com...
Stephen,
anytime you add a control dynamically to an ASP.NET page, if there is a
postback, you must recreate and add the control again, it doesn't
automatically "persist" across page reloads.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"stephen" wrote:

Hi,

I have a place holder and I have a checkboxlist in it?
why do i get a "System.NullRef erenceException : Object reference not set
to
an instance of an object." error why I try to get the selected value from
it?

Thanks,
Stephen

here is what I am doing?
Dim chkBoxList As CheckBoxList

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
ShowCheckBoxes( )
btn_Select.Text = "Display Selected"

End If
End Sub

Private Sub ShowCheckBoxes( )
Dim tString As String = "12px"
chkBoxList = New CheckBoxList
chkBoxList.Item s.Add(New ListItem("Is Enabled", "IsEnabled" ))
chkBoxList.Item s.Add(New ListItem("Is Active", "IsActive") )
chkBoxList.Repe atColumns = 2
chkBoxList.Repe atDirection = RepeatDirection .Horizontal
chkBoxList.Font .Size = FontUnit.Parse( tString)
phCheckButtons. Controls.Add(ch kBoxList)

End Sub
Private Sub btn_Select_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btn_Select.Clic k
If chkBoxList.Sele ctedItem.Text = "Is Enabled" Then
Response.Write( "<script language='javas cript'> { alert('Check Box
Selected.') }</script>")

End If

End Sub


Jun 9 '06 #5
Thanks Peter,

It worked.....

Stephen
"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in message
news:E2******** *************** ***********@mic rosoft.com...
Move the "ShowCheckBoxes " method call outside of the "If Not IsPostback"
block.
What's happening is when you click the button, that is a postback, and
since
your ShowCheckboxes call is inside this block, it never recreats the
controls. Sorry, I thought that was clearer than it apparently is.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"stephen" wrote:
Hi Peter and Jeremy,

Thanks for you replies
Actually I did try that option and it did fail,
in my code sample below:
In the click event again i call the "ShowCheckBoxes ()" again
but it still gives me the same error

Thanks,
Stephen

"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in
message
news:29******** *************** ***********@mic rosoft.com...
> Stephen,
> anytime you add a control dynamically to an ASP.NET page, if there is a
> postback, you must recreate and add the control again, it doesn't
> automatically "persist" across page reloads.
> Peter
>
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "stephen" wrote:
>
>>
>> Hi,
>>
>> I have a place holder and I have a checkboxlist in it?
>> why do i get a "System.NullRef erenceException : Object reference not
>> set
>> to
>> an instance of an object." error why I try to get the selected value
>> from
>> it?
>>
>> Thanks,
>> Stephen
>>
>> here is what I am doing?
>>
>>
>> Dim chkBoxList As CheckBoxList
>>
>> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>> System.EventArg s) Handles MyBase.Load
>> If Not Page.IsPostBack Then
>> ShowCheckBoxes( )
>> btn_Select.Text = "Display Selected"
>>
>> End If
>> End Sub
>>
>> Private Sub ShowCheckBoxes( )
>> Dim tString As String = "12px"
>> chkBoxList = New CheckBoxList
>> chkBoxList.Item s.Add(New ListItem("Is Enabled", "IsEnabled" ))
>> chkBoxList.Item s.Add(New ListItem("Is Active", "IsActive") )
>> chkBoxList.Repe atColumns = 2
>> chkBoxList.Repe atDirection = RepeatDirection .Horizontal
>> chkBoxList.Font .Size = FontUnit.Parse( tString)
>> phCheckButtons. Controls.Add(ch kBoxList)
>>
>> End Sub
>>
>>
>> Private Sub btn_Select_Clic k(ByVal sender As System.Object, ByVal e As
>> System.EventArg s) Handles btn_Select.Clic k
>> If chkBoxList.Sele ctedItem.Text = "Is Enabled" Then
>> Response.Write( "<script language='javas cript'> { alert('Check Box
>> Selected.') }</script>")
>>
>> End If
>>
>> End Sub
>>
>>
>>


Jun 9 '06 #6

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

Similar topics

1
2905
by: Timo | last post by:
I am trying to use the DropDownList_SelectedIndexChanged event on a dropdown which is dynamically populated with different values at runtime, depending on what the user has been doing. The dropdown works and the event fires except when the user selects the *first* item in the list, which appears to be the default selection, even though the...
3
1827
by: vitaly.tomilov | last post by:
I'm using an ASP.NET form to display data from my database table, and I'm doing it in the following way: XmlDataDocument doc = new XmlDataDocument(mydataSet); XPathNavigator nav = doc.CreateNavigator(); XslTransform xslTran = new XslTransform(); xslTran.Load("Transform.XSL"); xslTran.Transform(nav, null, Response.Output, null); This...
5
10877
by: andchoi | last post by:
I must be the dumbest ASP.NET 2.0 developer, because despite many different attempts, I am unable to resize a content place holder in the master page... Can anyone clue me in? It seems that the "resize grip handle" won't move despite I try pulling, pushing, kicking, punching, screaming. What am I missing here?
2
3021
by: J-T | last post by:
I am constructing an HTML text which I need to render in my ASP.NET page. string rssOutput = Posts.listPosts(Constants.WeblogSectionID); rssOutput contains html code and text.Then I create a literal control as follow: LiteralControl lit = new LiteralControl(rssOutput); lit.Text = lit.Text.Replace("&lt;","<");
2
3071
by: Brian | last post by:
Hello... I've created a master page in Visual Web Developer and it creates a content place holder. That's fine and all but I can't seem to resize it. Any suggestions? Thanks, Brian
0
1143
by: MasterChief | last post by:
I have a content place holder that is showing the summary of a sale. Is there a way to create a button in the content place holder that the person can click on to print just what is in the content place holder?
1
4817
by: lamuerte451 | last post by:
Hi: I am a newbie to asp.net 2.0 and am building an app with VS 2005 that will allow users to update records via the web. I have created a master page and then have placed Gridview and details view on the corresponding pages that the users will add records to. I am using a sql data source. My question is, how do I set the web page...
4
2087
by: darrel | last post by:
I have a DDL list along these lines: item value="1" text="a" item value="2" text="b" item value="3" text="c" item value="2" text="d" item value="2" text="e" item value="1" text="f" item value="1" text="g"
2
9614
by: greenMark | last post by:
Hi All, I'm relatively new to ASP.NET and Visual Web Developer 2008. I'm using a Master page with one content place holder. There is a Cascading Style Sheet file which is being refered by the master page file as follws "<link href="myStyleSheet.css" rel="Stylesheet" type="text/css"/>" Part of the Style sheet as follows: .textbox
0
7697
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...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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. ...
1
7672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
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...
0
6283
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...
1
5512
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...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.