Connecting Tech Pros Worldwide Help | Site Map

(un)check checkbox according to boolean parameter

Newbie
 
Join Date: Sep 2009
Posts: 3
#1: Sep 14 '09
Hello
I'm not a programmer. I'm afraid my question will be hilariously easy to ASP.NET programmers. Actually, I hope it will be. Please help.

In a .aspx file I'm trying to have a checkbox checked or unchecked based upon a parameter. I managed to find out which parameter I need and I can get in on screen with
Expand|Select|Wrap|Line Numbers
  1. <%=wiContext.getUserPreferences().getShowHints()%>
Output is either true or false.

Next I've been trying in every possible way I could think of to set the CHECKED flag using this getShowHints() return value. I guessed something like this would have worked:
Expand|Select|Wrap|Line Numbers
  1. <% if (wiContext.getUserPreferences().getShowHints()) then %>
  2.   CHECKED
  3. <% end if %>
It doesn't.
Anybody please help me out...
Thanks
Newbie
 
Join Date: Sep 2009
Posts: 3
#2: Sep 14 '09

re: (un)check checkbox according to boolean parameter


My own messy workaround:
Expand|Select|Wrap|Line Numbers
  1. <input type="Submit" ... OnClick="...;document.forms['ThisForm'].elements['ChkBxID'].checked=<%=wiContext.getUserPreferences().getShowHints()%>"/>
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#3: Sep 14 '09

re: (un)check checkbox according to boolean parameter


Do you have an ASP.NET checkbox?

For example:
<asp:CheckBox id="..." runat="server />

Or an HTML checkbox?

For example:
<input type="checkbox" ... />

You should be using the ASP.NET checkbox so that you can easily retrieve it's "checked" value on the server....
Newbie
 
Join Date: Sep 2009
Posts: 3
#4: Sep 15 '09

re: (un)check checkbox according to boolean parameter


Ah. There is such a thing as an "ASP.NET checkbox".
Like I wrote yesterday, I'm entirely new to ASP.NET. I'm using an HTML checkbox.

My "messy workaround" does work so I'm leaving it like that for now, but I'll certailny look into ASP.NET checkboxes later. Thanks!

BTW does an ASP.NET checkbox have advantages other than easy value retrieval?
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#5: Sep 15 '09

re: (un)check checkbox according to boolean parameter


You can use it in your server-side code to make logical decisions....

There are a lot of .NET controls that can make your life easier (sometimes they're complicated and make life harder for a bit but once you understand them you'll see that it is easier in the long run).


All the information you need on .NET controls can be found in the MSDN Library. This resource should get you pointed in the right direction... I recommend bookmarking the MSDN Library and using it as your primary resource when developing in .NET.
Reply