Showing posts with label checkbox. Show all posts
Showing posts with label checkbox. Show all posts

Thursday, March 29, 2012

Please change my readonly (Enabled=false) checkbox style as it is difficult to read.

Hi,

This has been bugging me for a while so any help is appreciated.

How do I change the style of a readonly checkbox? (i.e. Enabled = False) - it's very difficult to read

I am displaying a set of checkbox based on some database query which works fine - however the faded checkbox and tick are not easy to see. I don't want to use skin files/themes if I can help it.

The only option I can think of is to display the database results (1 or 0) as images (1 for empty checkbox and 1 for full checkbox) but it seems a bit over the top.

I may be missing something simple but I have tried various checkbox parameter settings to no avail.

Many thanks

MrCadburysParrot

I had the same concern and I wound up using images. Over the top? That's all I could get working...

 <asp:TemplateField HeaderText="Freeze Definition" SortExpression="FreezeDefn"> <ItemTemplate> <asp:Image ImageUrl="../../images/CheckBoxYes.gif" ID="imgFreezeDefnTrue" runat="server" Visible='<%# Convert.ToBoolean(Eval("FreezeDefn"))%>'> </asp:Image> <asp:Image ImageUrl="../../images/CheckBoxNo.gif" ID="imgFreezeDefnFalse" runat="server" Visible='<%# !Convert.ToBoolean(Eval("FreezeDefn"))%>'> </asp:Image> </ItemTemplate> <EditItemTemplate> <asp:CheckBox ID="cbxFreezeDefn" runat="server" checked='<%# Convert.ToBoolean(Eval("FreezeDefn"))%>'> </asp:CheckBox> </EditItemTemplate> <FooterTemplate> <asp:CheckBox ID="cbxNewFreezeDefn" runat="server" > </asp:CheckBox> </FooterTemplate> <ItemStyle HorizontalAlign="Center" /> <HeaderStyle HorizontalAlign="Center" Width="120px" Wrap="True" /> <FooterStyle HorizontalAlign="Center" /> </asp:TemplateField>

Hi,

Thanks for the response. It does seem the only way to do it. I ended up using

<asp:ImageID="chkD7Adjusted"runat="server"ImageUrl='<%# DisplayCheckGraphic(Eval("Interlocks")) %>'/>

The function DisplayCheckGraphic then returns a string value (depending on the Interlocks value) denoting the appropriate Image URL.

I'll leave the post running for a few days to see if anyone has a direct answer to the checkbox issue - if not I will allocate your response as the answer as it was same as the method that I am currently using.

Thanks

MrCadburysParrot


You can do many things such as setting style etc around it.

one way is to

Get the checked event in javascript and then

e.ParentNode.style.border =(e.checked ? 'outset' :' ' );

or for a simple readonly setting its style to outset, so that it becomes raised.


Yeah, you could stick it on the stylesheet too. That would be much neater. I'm not a designer though so I don't do much with styles beyong making something readable. I really would like to put some time into sexy-ing up my pages but I'm too busy developing functionality and working on ETL and such. So is everyone else on the team - the guy with the design skills is busy writing code generators.

Plus I can't stand CSS language. Why is it different than the syntax used for styles in ASP? The don't even have the same attributes... grr. Does silverlight encapsulate this kind of stuff by any chance? Is there something on the horizon that will give us a styling GUI? Thanks.


Charles Asbornsen:

Yeah, you could stick it on the stylesheet too. That would be much neater. I'm not a designer though so I don't do much with styles beyong making something readable. I really would like to put some time into sexy-ing up my pages but I'm too busy developing functionality and working on ETL and such. So is everyone else on the team - the guy with the design skills is busy writing code generators.

Plus I can't stand CSS language. Why is it different than the syntax used for styles in ASP? The don't even have the same attributes... grr. Does silverlight encapsulate this kind of stuff by any chance? Is there something on the horizon that will give us a styling GUI? Thanks.

Charles

CSS is a standard and rather a markup where as Asp.net is a framework and CSS existed way before Asp.net and imagine sugar and water cannot be same thing, however sugar provides sweetness to water. Silverlight is imagine a plugin like flash and CSS will still be at play. Yes there are skins but they also work with cSS.

Best regards


A poetic allusion for a buggering annoyance. Big Smile I appreciate the "objectiness" of CSS (kind of like truthiness), and I'd like to go through all my code and CSS the whole works, but that has to wait until all our deliverables are, um, delivered. I could really use some CSS training. I just wish I could go to something like powerpoint, draw my styled control in that, and then say "hey you, this is your style when selected, and this is your style when mouseover" and so forth without 28 lines of code...

Monday, March 26, 2012

Please help

Hi,

I have a login screen with a remember user checkbox. I am storing the Login
Information (UserName and Password) on the client machine using cookies. The
text boxes used to accept the username and password are both ASP server
controls. The TextMode property for the box accecpting password is set to
"password". I save the login information when the user checks the "remember
user" checkbox (using cookies) and retrieve this information every time he
tries to relogin(ie when the login page is requested ). The problem is that
the password cannot be displayed in the text box(TextMode set to "password")
as astrix and is seen as blank (Though it is correctly stored in the cookie
as seen using page level trace)

I am using Microsoft Development Environment 2002 version 7.0.9466 &
Microsoft.NET framework 1.0 version 1.0.3705

Any suggestions would be highly appreciated.

TIA,

GaryAn "input type=password" (which is NOT an "input type=text" textbox object)
HTML object can not have its' value persisted. This is a Security
consideration. What would be the point of requiring a password if ANY user
that opens that URL in the browser on the machine with the password stored
in a cookie doesn't have to type in the password?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"Gary" <msnews@.microsoft.com> wrote in message
news:eh94ffVZDHA.2344@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I have a login screen with a remember user checkbox. I am storing the
Login
> Information (UserName and Password) on the client machine using cookies.
The
> text boxes used to accept the username and password are both ASP server
> controls. The TextMode property for the box accecpting password is set to
> "password". I save the login information when the user checks the
"remember
> user" checkbox (using cookies) and retrieve this information every time he
> tries to relogin(ie when the login page is requested ). The problem is
that
> the password cannot be displayed in the text box(TextMode set to
"password")
> as astrix and is seen as blank (Though it is correctly stored in the
cookie
> as seen using page level trace)
> I am using Microsoft Development Environment 2002 version 7.0.9466 &
> Microsoft.NET framework 1.0 version 1.0.3705
> Any suggestions would be highly appreciated.
> TIA,
> Gary

Saturday, March 24, 2012

Please Help - Where is the mistake in my code

Hi all

When I run this app, select the checkbox and press the calculate button i get the following error:

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] nihe.SimpleRent.calculate(Object source, EventArgs e) +173 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1292

My code is as follows, does anyone know what i have done wrong, any help/advice would be very much appreciated.

<%@dotnet.itags.org. Page Language="VB" Debug="true"Inherits="nihe.SimpleRent" ContentType="text/html" ResponseEncoding="iso-8859-1" %><html><body> <form runat="server"> Bathroom with W/C: <asp:CheckBox id="bath_wc" runat="server"></asp:CheckBox> <p> <asp:button id="calcbutton" onclick="calculate" runat="server" text="calculate"></asp:button> </p> </form></body></html>
' SimpleRent.vb'Imports SystemImports System.WebImports System.Web.UIImports System.Web.UI.WebControlsNamespace nihePublic Class SimpleRent : inherits page protected withevents bath_wcAs system.web.ui.webcontrols.checkbox protected withevents row_bwcAs system.web.ui.webcontrols.TableRowPublic sub calculate(source asObject, e as EventArgs) if bath_wc.checked then bath_wc.text ="+3" Context.Items.Add("bath_wc", bath_wc.text) row_bwc.Visible = bath_wc.checked end ifserver.transfer("SimpleResult.aspx")End SubEnd ClassEnd Namespace
<%@dotnet.itags.org. Page Language="vb" %><script runat="server">Sub Page_Load(Source asObject, E as EventArgs) cell_bwc.text ="Bathroom With WC" value_bwc.text = Context.Items("bath_wc")End Sub</script><html><body><form> <asp:Table runat="server"> <asp:TableRow id="row_bwc"> <asp:TableCell id="cell_bwc"></asp:TableCell> <asp:TableCell id ="value_bwc"></asp:TableCell> </asp:TableRow> </asp:Table></form></body></html>

Where did you get this code from?

<html>
<body>
<form>
<asp:Table runat="server">
<asp:TableRow id="row_bwc">
<asp:TableCell id="cell_bwc"></asp:TableCell>
<asp:TableCell id ="value_bwc"></asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>

I see 2 html parts in the code you posted.

Thanks


Because your Calculate method is encapsulated in a page that does not exist. Therefore, "row_bwc" does not exist.

For some reason, it seems you have attempted to create an inheritable base page that is actually a "real" page?


Sorry should have been more specific.

The code show is actaully three seperate pages

page one, codebehind for page one and results page.

Hope this clarifies things

Sorry

Kevin


The last line of your Calculate method attempts to executerow_bwc.Visible = bath_wc.checked. No instance of row_bc has been created. Therefore,row_bc is a null reference.

Remember, there's no row_bc on page one. It's only on the results page.


Lee thanks for reply

So where do i need to reference row_bwc and how do it do it?

Thanks in advance

Kevin


It seems you mix 2 web pages.You have 2 webpages A and B,you can only access controls of A in codebehind of A.

"So where do i need to reference row_bwc and how do it do it?"

You have 2 choice .

1: Combine page one and result page to a single page.That means add:

 <asp:Table runat="server"> <asp:TableRow id="row_bwc"> <asp:TableCell id="cell_bwc"></asp:TableCell> <asp:TableCell id ="value_bwc"></asp:TableCell> </asp:TableRow> </asp:Table>

to page one and don't forget add code in pageload to page one. Then use YourControl.visible to display or hide controls.

2: pass parameter (like row_bwc.Visible,etc )to SimpleResult.aspx then do the action within SimpleResult.aspx.


Kipster:

Lee thanks for reply

So where do i need to reference row_bwc and how do it do it?

Thanks in advance

Kevin

You need to pass the value to set the visibility of row_bwc to the SimpleResult page. You could do this in one of the many ways that you would normally pass values between pages -- like in a QueryString, or drop the Server.Transfer and do a crosspost instead. Let me know if you need an example.

Wednesday, March 21, 2012

please help me on multiple update recordset

when i select 2 records to update from checkbox, it only updated 1 record. can anyone help me?

code
====

<%
if request("deleted")="" then
response.redirect"member.asp"
end if
set rs=server.createobject("ADODB.Recordset")
sql="select pause from Users where id IN ("&request("deleted")&")"
rs.open sql,cn,1,2
if not rs.eof then
rs("pause")="1"
rs.update
end if
rs.close
set rs=nothing
closeCN
%><script
javascript:document.location='member.asp';
</script
=======================================================Instead of if ... then go for

while not rs.eof
rs("pause")="1"
rs.update
rs.movenext
wend

:))
Devendra.
Thanks cdnaik
I't works.
:)

Friday, March 16, 2012

please help me with validation

Hi, I am trying to validate 3 HtmlInputCheckBox controls:
<input type="checkbox" id="cbx1" runat="server">
<input type="checkbox" id="cbx2" runat="server">
<input type="checkbox" id="cbx3" runat="server">
<asp:button id="validate" Text="OK" runat="server"/>
<asp:ValidationSummary id="valsummary" ShowSummary="False" ShowMessageBox="True" runat="server"/>
I need at least one of them to be checked and popup a messagebox (as of the validationsummary control) that tells the user if no checkbox is checked.
I appreciate your help!
Sincerely,
PeleP
There is no validator supplied with ASP.NET that can evaluate an individual checkbox. You have several choices:
1. Use a CustomValidator. Create your own client-side code to handle the evaluation. After all, to show the messagebox, you *must* have client-side validation. (Its just a requirement of the validator controls.)
2. Replace your checkboxes with a CheckBoxList control. The RequiredFieldValidator can detect that its blank and report an error. This is the easiest solution, but doesn't work if you have a format that doesn't match what the CheckBoxList allows.
3. Switch to an alternative validation system which can handle checkboxes. MyProfessional Validation And More supplies 25 validators including several involved for creating this case. You would use my MultiConditionValidator like this:
<vam:MultiConditionValidator id="MCV1" runat="server" ErrorMessage="Please select one" Operator="OR">
<Conditions>
<vam:CheckStateCondition ControlIDToEvaluate="cbx1" Checked="True" />
<vam:CheckStateCondition ControlIDToEvaluate="cbx2" Checked="True" />
<vam:CheckStateCondition ControlIDToEvaluate="cbx3" Checked="True" />
</Conditions>
</vam:MultiConditionValidator>
This will generate client-side support. It supports many more browsers than ASP.NET 1.x validation does. And its message box option shown when the user submits will show the error message.
Hi! Thanks for your reply!

I do not think the RequiredFieldValidator control works with checkboxlist controls. Maybe it does in "asp.net" 2.0?

Your validation controls look interesting but I think I will try to do it myself.
It seems to be a little complicated though, but I will give it a go.

Thanks anyway!

Sincerely,
PeleP
The RequiredFieldValidator does work with the CheckBoxList and RadioButtonList. It does not work with ordinary CheckBox and RadioButton controls.
strange... i have tried that, and i cannot make it work. can you give me a quick example how you would do it?
this is what i have learned:
<asp:checkboxlist id="cb1" runat="server">
...items...
</asp:checkboxlist>
<asp.requiredfieldvalidator id="rfv" controltovalidate="cb1" runat="server"/>
so, are you sure? this is the last time... i will try to not disturb you further with stupid questions...
Sincerely,
PeleP
It is my understanding that's how to set it up. The RequiredFieldValidator has a property called InitialValue which has a string that is the text representing "blank". It defaults to "". When evaluating any type of list control, if there is no selection, the control has a value of "" which should match to InitialValue="".
There is one more piece. Each <asp:ListItem> has a Value property too. These must be assigned to something other than "".
<asp:ListItem value="1">text here</asp:ListItem>

Sorry. The RequiredFieldValidator does NOT word with the CheckboxList.

Here's why -- Remember that the builtin validation controls also render client script. It gets the required validation property from the value attribute of the HTML element that gets rendered on the client. Since an HTML value attribute can't be two things at once, the validated control must have a single logical value on the client.

This is why RadioButtonList can be validated, but CheckBoxList cannot


Hi Lee,

You are correct. I don't know where my head was when I was writing those posts. I suspect I confused the RadioButtonList's support with the CheckBoxList. Oh well. Thanks for clearing it up.


Hello, thank you both for following up this post. Now I understand why it is not possible, so I can and will leave it for now. Maybe the new asp.net 2.0 can give a solution to this!? I will look into that later.

Anyway, I temporarily solved it by using ordinary CheckBox's and have validated them using some client code.

Thanks for your help!

Sincerely, PeleP


Yes, there are workarounds, thank goodness. Probably the easiest is to create a customvalidator with both server and client-side code.

ASP 2.0 does not provide a solution. Understand, the inability to validate the CheckBoxList never really was a limitation of ASP in the first place. It's really caused by the limitations of HTML. (Remember, no matter what, the server still has to render HTML at the end of the whole deal.) There is no value= attribute of HTML checkboxes that let them determine the state of other checkboxes. Therefore, a built-in ASP validator couldn't automatically render "generic" client-side code for it.