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 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
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
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
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
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 >> >> >> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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?
|
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("<","<");
|
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
| |
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?
|
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...
|
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"
|
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
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |