Checked=Checked

 

I am dynamically writing out checkboxes on a page.

 

I have 2 link buttons on the page that sets a boolean variable to True or False. This boolen is set in Page_PreInit and is used to Select or Deselect all the Checkboxes as they are written out. A Select ALL, Deselect ALL type of thing. At least that is the plan.

As the page is being written out I do this for each checkbox and then add it to a table cell control that it added to a table row and on. tc is the table cell.

 

  Dim chkItem As CheckBox = New CheckBox
chkItem.ID = "chkRecommend" + drMember("ID")

chkItem.Checked = bChecked
tc.Controls.Add(chkItem)

 

 Where bChecked is that boolean I mentioned above.

Now, not matter what the value of bChecked, True or False, the checkbox that is written out is always checked.  The html that is written out looks like this.

<input id="ctl00_LeftContent_chkRecommendBert" type="checkbox" name="ctl00$LeftContent$chkRecommend32" checked="checked" />

Note the checked="checked" property. This is always set.

I have tried only setting the .Checked property if the value of bChecked is True. 

I have tried setting the .Checked property to bChecked.ToString(). 

I have tried setting the .Checked propery to bChecked.ToString().ToLower()

No matter what I do, the checkboxes are always ticked. 

Now I'm mighty ticked off.  What is going on here?

Thanks in advance

 

 

 

 

                         

 

 

 

0
Dobly
1/12/2009 12:48:39 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

18 Replies
1182 Views

Similar Articles

[PageSpeed] 34

Have you looked at the value of bChecked prior to assigning the value to the various CheckBox controls?  Is it possible that it either not being properly set from the Select or Deselect All functionality or that it is getting reset to a value of true somewhere between setting the Select All CheckBox and processing the individual CheckBox controls?


Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/12/2009 1:40:55 AM

Oh yes. I am 100% positive that bChecked is set to True or False as it should be.

Check out this screen shot where bChecked was False.

It is a look at the dynamic checkbox just as I am about to add it to the table cell.

Checkbox.Checked = False 

 So, It knows it is False. Yet when the page runs the checkbox is ticked and the HTML says checked="checked". 


 

0
Dobly
1/12/2009 2:46:00 AM

Where is bChecked assigned with the Checked property value from chkItem?


Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/12/2009 3:45:26 AM

 From chkItem? It is never assigned a value 'from' chkItem'.

 bChecked is set in  Page_PreInit

  

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
Dim sControl As String = GetPostbackControl(Me.Page)
If (sControl <> "") Then
If
(sControl = "lbAdd") Then
MyCount = MyCount + 1
ElseIf (sControl = "lbDeselectAll") Then
bChecked = False
ElseIf
sControl = "lbSelectAll" Then
bChecked = True
End If
End If

End Sub

 It is here I am reacting to what caused the postback.

 Now when I comes to assigning the value of bChecked to the new checkbox as I created, I have tried this.

  

chkItem.Checked = bChecked
chkItem.Checked = bChecked.ToString()
chkItem.Checked = bChecked.ToString().ToLower()

I have also tried only setting the .Checked when bChecked is True. 

If bChecked Then
' Insert any one of the lines above
End If
 
So even if I don't set anything, the checkboxes render as checked.

 

 

0
Dobly
1/12/2009 4:19:24 AM
Maybe this line   [ sControl = "lbDeselectAll" ]  is never reached. Alternatively, try dynamically creating labels that will hold the value of sControl variable. You can investigate from this stage.

Bind GridView to Dynamically created DataTable | Bind DataTable to DropDownList

My Blog
0
shahed
1/12/2009 7:03:08 AM

 Also, you can modify your if statement from

ElseIf sControl = "lbSelectAll" Then
bChecked = True
to
ElseIf sControl = "lbSelectAll" Then
bChecked = False
and check if the checkboxes are now checked or not. If it checked, then you are overwriting the checked property somewhere else. 

 


Bind GridView to Dynamically created DataTable | Bind DataTable to DropDownList

My Blog
0
shahed
1/12/2009 7:05:21 AM

The value of bChecked is not in question. It is set correctly. As you can see in my screen shot above, through the use of bChecked I can set the .Checked property of the checkbox to False. And as I am about to add it to the table cell control, it is Checked = False. 

 However, the problem still exists.

 Could the fact it is in an Ajax update panel have anything to do with this. I'm grasping at straws now. 

 

Edit: Nope. I just removed the update panel and it made no difference. 

 

 

0
Dobly
1/12/2009 9:18:37 AM

shahed.kazi:
Maybe this line   [ sControl = "lbDeselectAll" ]  is never reached. Alternatively, try dynamically creating labels that will hold the value of sControl variable. You can investigate from this stage.
 

I have stepped through the code many time. I have set breakpoints and looked at the value of bChecked.  It is getting set correctly. 

 

0
Dobly
1/12/2009 9:24:59 AM

Okay, then, after the chkItem.Checked property is set to bChecked, what happens? In what method does this occur?

Actually, the better question is: Is this being set in Page_Load?


Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/12/2009 1:57:52 PM

 The variable bChecked is set in Page_PreInit.  This code it working as expected

 Then Page_Load is called and the function that creates the dynamic table including these stupid checkboxes is called last. 

 This screen shot shows the moment I am creating the checkbox along with the value of bChecked. 

 

 Yet the checkbox on the page once loaded is still checked. 


0
Dobly
1/12/2009 10:47:19 PM

When the Page_Load is called, the ViewState is set for your controls.  So, if the controls were true prior to postback, the ViewState remembers true and accordingly makes them as true.

Anything that is set for a control prior to the Page_Load and uses ViewState will be overridden.  Therefore, you will need to make your updates within the Page_Load to overcome the previous ViewState values.


Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/12/2009 10:58:58 PM

 

Careed:

Anything that is set for a control prior to the Page_Load and uses ViewState will be overridden.  Therefore, you will need to make your updates within the Page_Load to overcome the previous ViewState values.

Like I said above.. "Then Page_Load is called and the function that creates the dynamic table including these stupid checkboxes is called last. "

 That is, the last bit of code in Page_Load, is the code that creates the table with the checkbox in it. 

 

 

0
Dobly
1/12/2009 11:25:17 PM

Have you stepped through the entire application in the debugger from start to finish?  Besides the wicked things that dynamic controls can do to your application, there are a lot of different things going on within yours.  If you see the Checkboxes marked one way in the debugger, then you should be able to see when they are put back to the value you don't want.

Can you provide the entire Page_Load?


Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/12/2009 11:53:25 PM

 There is nothing in the Page_Load that would effect the checkboxes. Especially as the checkboxes are created last. ie: as the final act of Page_Load

  And yes I have stepped through, all the way though again and again. Regardless of that, if the final Checked value on a checkbox is False, it displays as Checked once it gets back to the site.

0
Dobly
1/13/2009 4:09:01 AM

Well, I'm at a loss.  I cannot see how the Checked values are changing back if you are actually setting them in the Page_Load.

For me, I would usually go back to a good starting point.  Specifically, in your case, I would try creating a test page that contains a CheckBox and a GridView with a CheckBoxField.  Nothing is dynamically built.  Then, go through the some process where if the user selects the CheckBox, all of the CheckBoxField elements are selected, and vice versa for unselecting.  Then move toward building your dynamic controls one-by-one until you have either recreated the original webpage, though without the same bug, or you find the point where the issue occurs.


Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/13/2009 4:50:52 AM

Yeah. This really has me stumped. It defies logic. I should have learned PHP when I had the choice? Smile

 I have spent so much time on this it's not funny. Now I'm thinking I'll need to look for a javascript solution as ASP.NET seems incapable of this most basic operation. I just need to tick, or untick all the checkboxes. Is that too much to ask? 


Thanks for your help Careed. I'll post again when I find a solution.  Unless someone else has some idea what is happening?

 

 

0
Dobly
1/13/2009 5:59:21 AM

Actually, when you're using ASP.NET straight up, it is a very robust development system.  However, when you introduce the prospect of creating a control on the fly, it can be a nightmare.  This is mainly because you have to do all of the plumbing and wiring that the Framework does for you when you put a control on a web form.  The more complex the control, the bigger the potential headache.

Don't get me wrong, I like this aspect of ASP.NET, something that the scripting languages can't exactly provide.  That's why I try to minimize using controls built on the fly as much as possible.

Well, if anything else comes to mind, I'll post it here.


Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/13/2009 1:16:32 PM
Try commenting all the code out which sets the values of the checkboxes then set try just setting one of them to unchecked using checkbox.checked=false. I have had similar problems before and it always comes down to either the viewstate resetting my controls or some code resetting them. It is just a case of chipping away at narrowing the problem down. I also sometimes have to build a blank project and try to replicate the problematic functionality knowing that no other code could possibly be having an effect.
0
coolblue
1/13/2009 2:54:03 PM
Reply:

Similar Artilces:

Check out/check in
Hello How can i use the process check out/check in in PowerBuilder 8.0.3 ? We work in network. The Source Control is PB Native. I don't understand what is the parameters of Source Control ? Thank you Have you looked the PB8 User's guide? Chapter 3 talks about source control. -- Evita Chapa Senior Systems Analyst II Command Technologies Inc. <Herv� Bareth> wrote in message news:3f69ba0a.592b.846930886@sybase.com... > Hello > > How can i use the process check out/check in in PowerBuilder > 8.0.3 ? We work in network. The Source Control is PB Na...

Check-in/Check-out
I'm having some difficulty with powerbuilder's check-in/check-out operation. When I check an object back in, the .pbl the object is being moved from is destroyed. Has anyone else experienced this and is there a fix? Cheers, Tom Thomas F. (Tom) Massey wrote: > > I'm having some difficulty with powerbuilder's check-in/check-out > operation. When I check an object back in, the .pbl the object is > being moved from is destroyed. > > Has anyone else experienced this and is there a fix? > > Cheers, > > Tom The prob...

Check In/Check out
I am using PowerBuilder 9. The undo check out is right next to the check in. This is a big problem! I so easy to select Undo check out and lose all of your changes. I lost 8 hours of work yesterday because of it. I know I should be more careful. However, there should be a "Are you sure" some where also. PLEASE FIX!!!!!!!!!!!!! -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ This isn't the tech support line, it's an end-user forum. If you want to report a bug, use CaseXpress and either open a case or report a bug ...

Check out/check in
Hello How can i use the process check out/check in in PowerBuilder 8.0.3 ? We work in network. The Source Control is PB Native. I don't understand what is the parameters of Source Control ? Thank you Better to ask this in the source control group. Lots of posts on PBNative -- Evita Chapa Senior Systems Analyst II Command Technologies Inc. <Herv� Bareth> wrote in message news:3f69678e.7b3a.846930886@sybase.com... > Hello > > How can i use the process check out/check in in PowerBuilder > 8.0.3 ? We work in network. The Source Control is PB Native. ...

Check In Check Out
I have some source code that I need to modify and it was sent to me in a Registered status. Therfore, when I open any object it says " 'object name' is registered but not checked out and therefore can not be overwritten. Open anyway?" Then when I try to check it out, I get "PBNative checkout not allowed for registered objects." How can I get around this? When I look under the "Source" menu, all the items concerning registered are grayed out. TIA Option1:Copy the object(Only) to someother pbl and try . Option2:If You have any SCC Expo...

Check in
Hi all. I am migrating from PB 7.0 to PB 10.5, After migrating my first application i am trying to work on my first window but i'am not able to find out the way to CHECK it OUT. Wher do i can find "check out/check in" functions ?? TIA Mario Parietti What source control are you using? Have you configured it? Right click on your Workspace and check the source control tab to see if you've got it set up. "Mario Parietti" <mparietti@intercad.ch> wrote in message news:451283e0$1@forums-1-dub... > Hi all. > I am migrating from PB...

VS.Net Check In/Check Out Function
Hi All, I work on a team of developers who are just trying to get started with ASP.Net.  I've been doing development for 2+ years so it's not new to me but my colleagues have asked a question about the VS.Net environment that I can't answer.  We're trying to find out if there is some sort of Check In/Check Out function with Visual Studio.Net.  I've never worked in a team environment before so I couldn't answer this.  The reason we're wondering is because we're planning on setting up our online forms in a DotNetNuke style environment (one page, loads user contro...

checking checkbox is checked or not using checkbox.checked
Hi,my checkbox is<asp:CheckBox ID="Chkcity" runat="server" Text="My own city"  OnCheckedChanged="EventHandler"/>code behind: Private Sub Chkcity_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chkcity.CheckedChangedif (Chkcity ...............)end if End SubERROR    'EventHandler' is not a member of 'ASP.bpoaddjob_aspx'.    Please Mark the post as "ANSWER" if it helps you I think it should be like this:<asp:CheckBox ID="Chkcity"...

Check All Check Box While Check Header CheckBox
 hello...I have two grid on same page...both grid contains header checkbox and item checkbox i want that if use check header checkbox then all item check box checked,i have javascript for this functinality but problem is that when i click on header check box of first grid then checkbox of second grid also checked that i dnt want i want to perform this operation on one grid at one time.i have attache my script also...plz help me....thanks<script type="text/javascript">        function SelectAll(ID)      &nbs...

how to check if a check box created in runtime checked or not?
I have a webform that have mutiple collectios of check boxes created on run time ( database driven) what is the best way to loop between them and get which ones has been checked by a user and save the results back to the database below a portion of my code. i am adding the checkbox to cell table which added to a row, then to a table, finlally the table added to a place holderwhile (drProfileList.Read()) {HtmlTableRow tr = new HtmlTableRow(); HtmlTableCell tc = new HtmlTableCell();CheckBox chkbox = new CheckBox(); chkbox.ID = drProfileList["RoleID"].ToString();chkbox.T...

How to check how many check boxes are checked in the gridview
I am trying to make a javascript client fucntion to restrict no more then two rows could be selectedI have following in the itemtemplate of the gridview [although it is telerik control but same technique should be applied] <radG:GridTemplateColumn UniqueName="chkCheck">                    <HeaderStyle  HorizontalAlign="Right" />                    <HeaderTempla...

Web Form designer extremely slow and insists on checking out web.config
VS suddenly started acting very strangely. It takes a very long time (~ 3 minutes) to render a simple form, and insists on checking out web.config. If I don't allow it to check out web.config it renders every control as a grey box labeled "Error Creating Control" This project has been working fine for weeks and I made no changes to the web forms. I have restored the project from backup and the problem remains. I have also re-installed VS. The project builds and runs fine - it's only the web form designer that has gone wonky. The markup is fine and the codebehind is fi...

How to check for the existing user in database and using custom validator how to check check box is checked or not?
Hi Friends, For Registration page i want to check if that user already exist in database or not? and i also have to check if user have check the checkbox for i agree then only he will be able to complete registration. here i am sending my design. and all validation i have done all validation except these two.<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PRIZE MLS</title><link href="css/style.c...

Check in/Check out questions
--------------2AFBC72935EA78376A16761F Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello ! I have some problems with using the check in/check out system. * I copied my PBL and deleted all entries in the copy, so then the copy was empty except the application. Then I opened my orginal PBL and checked out some components. As I saw, the unchecked components can't be edited any more, OK, but I could start my application. OK. My problem was in the copied PBL, because there was (of course) only the uncheck compone...

Web resources about - Checked=Checked - asp.net.web-forms

Resources last updated: 1/16/2016 1:43:12 AM