473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

textbox value greater than zero? Client-side check?

I'm not sure how to exactly ask this, but expect that it's a Javascript
solution. However, I'll ask the question and maybe someone can point
me to some existing code that will do what I need.

I have an Asp.Net app that's in 2.0 framework. I have a page that is
sort of a storefront sort of page that has a product, a quantity and a
button for "Add To Cart" and one for "Add To Wishlist".
I'd like to disable those two buttons if the quantity is not greater
than zero.
Can someone help?

Nov 17 '06 #1
13 3766
Hi,

HockeyFan wrote:
I'm not sure how to exactly ask this, but expect that it's a Javascript
solution. However, I'll ask the question and maybe someone can point
me to some existing code that will do what I need.

I have an Asp.Net app that's in 2.0 framework. I have a page that is
sort of a storefront sort of page that has a product, a quantity and a
button for "Add To Cart" and one for "Add To Wishlist".
I'd like to disable those two buttons if the quantity is not greater
than zero.
use compare-validators for things like this - these will validate data on
the client-side. Set your button's CausesValidation-property to True, add a
compare-validator for each textbox, linking them to another. If you need
several different validation-groups, use the ValidationGroup-properties. If
you'd rather like to display a single message (as opposed to or in addition
to showing error-messages right next to the control), use a
ValidationSummary-control.

Cheers,
Olaf
--
My .02: www.Resources.IntuiDev.com
Nov 17 '06 #2
bpd
Off the top of my head without seeing your code: I suppose you could
default the buttons to be disabled and fire the "TextChanged" event
when a value is entered in a quantity textbox or the
"SelectedIndexChanged" event if it is a drop down list. In these
events, you can then enable the buttons. You will probably need to put
code in the events to check if your qty is greater than 0 or not and
enable/disable accordingly (the user may remove items from cart as well
as add?).

HockeyFan wrote:
I'm not sure how to exactly ask this, but expect that it's a Javascript
solution. However, I'll ask the question and maybe someone can point
me to some existing code that will do what I need.

I have an Asp.Net app that's in 2.0 framework. I have a page that is
sort of a storefront sort of page that has a product, a quantity and a
button for "Add To Cart" and one for "Add To Wishlist".
I'd like to disable those two buttons if the quantity is not greater
than zero.
Can someone help?
Nov 17 '06 #3

HockeyFan wrote:
I'm not sure how to exactly ask this, but expect that it's a Javascript
solution. However, I'll ask the question and maybe someone can point
me to some existing code that will do what I need.

I have an Asp.Net app that's in 2.0 framework. I have a page that is
sort of a storefront sort of page that has a product, a quantity and a
button for "Add To Cart" and one for "Add To Wishlist".
I'd like to disable those two buttons if the quantity is not greater
than zero.
Can someone help?
Olaf's advice looks good. Validators are ideal for situations like
this.

Nov 17 '06 #4
bpd
I believe they want to enable/disable buttons and not display messages
when the qty is 0. Please advise on how to do this with validators.

Eric wrote:
HockeyFan wrote:
I'm not sure how to exactly ask this, but expect that it's a Javascript
solution. However, I'll ask the question and maybe someone can point
me to some existing code that will do what I need.

I have an Asp.Net app that's in 2.0 framework. I have a page that is
sort of a storefront sort of page that has a product, a quantity and a
button for "Add To Cart" and one for "Add To Wishlist".
I'd like to disable those two buttons if the quantity is not greater
than zero.
Can someone help?

Olaf's advice looks good. Validators are ideal for situations like
this.
Nov 17 '06 #5
"Eric" <ve****@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Olaf's advice looks good. Validators are ideal for situations like
this.
I disagree - I think bpd has the right idea...
Nov 18 '06 #6
Hi,

Mark Rae wrote:
>Olaf's advice looks good. Validators are ideal for situations like
this.

I disagree - I think bpd has the right idea...
thing is, you'd need server-side code in order to actually enable the
button. If there's a client-side-way of dealing with this (i.e. enabling a
control), then I'd sure like to know ...

Cheers,
Olaf
--
My .02: www.Resources.IntuiDev.com
Nov 18 '06 #7
"Olaf Rabbachin" <Ol*********@IntuiDev.comwrote in message
news:eA**************@TK2MSFTNGP04.phx.gbl...
thing is, you'd need server-side code in order to actually enable the
button. If there's a client-side-way of dealing with this (i.e. enabling a
control), then I'd sure like to know ...
??? You can enable / disable a control with client-side JavaScript just as
easily as you can with server-side C#.

<script type="text/javascript">

function enableButtons
{
document.getElementById('MyButton').disabled =
(parseInt(document.getElementById('MyTextBox').val ue) == 0);
}

</script>

<input type="text" id="MyTextBox" onblur="enableButtons();" />

<input type="button" id="MyButton" value="Save" />
Nov 18 '06 #8
Hi,

Mark Rae wrote:
??? You can enable / disable a control with client-side JavaScript just as
easily as you can with server-side C#.

<script ...
great, thanks! I simply have lots to learn concerning JS. :-)
Since we're at this - assuming the following script-code ...

If Not ClientScript.IsClientScriptBlockRegistered("Enable Go") Then
Dim strJS As String = _
"<script language=""JavaScript""" & _
"function enableGo(chk) {" & _
"document.getElementById(""" & cmdGo.ClientID & """).disabled = " & _
"(document.getElementById(chk).checked == false);" & _
"}" & _
"</script>"
ClientScript.RegisterClientScriptBlock(Me.GetType, "EnableGo", strJS)
End If

.... which is supposed to enable a button if the passed checkbox's ID
(ClientID) is checked. With controls that have been created at design-time,
this will work just fine (as with cmdGo.ClientID), but in my case the
checkboxes are created dynamically.
Hence, I'm doing the following for each checkbox being created:

dim chkBox as New CheckBox
....
chkBox.Attributes.Add("onclick", "enableGo(" & chkBox.ClientID & ")")

However, instead of the ClientID, only the ID will be passed and the script
fails. Any clue on how to get this working for dynamic controls?

Cheers,
Olaf
--
My .02: www.Resources.IntuiDev.com
Nov 18 '06 #9
"Olaf Rabbachin" <Ol*********@IntuiDev.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Mark Rae wrote:
>??? You can enable / disable a control with client-side JavaScript just
as
easily as you can with server-side C#.

<script ...

great, thanks! I simply have lots to learn concerning JS. :-)
JavaScript remains as important in web development now as when it first
appeared - ASP.NET hasn't changed that at all...
"<script language=""JavaScript""" & _
"<script language=""text/javascript""" & _

if you want it to be XHTML-compliant...
However, instead of the ClientID, only the ID will be passed and the
script
fails. Any clue on how to get this working for dynamic controls?
I assume you're creating the dynamic controls in Page_Init - if not, you
need to...
Nov 18 '06 #10
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"<script language=""text/javascript""" & _
Sorry, I mean "<script type=""text/javascript""" & _
Nov 18 '06 #11
Hi,

Mark Rae wrote:
>However, instead of the ClientID, only the ID will be passed and the
script fails. Any clue on how to get this working for dynamic controls?

I assume you're creating the dynamic controls in Page_Init - if not, you
need to...
I do, but still, the dynamic checkboxes won't show the ID rather than the
ClientID. Since I'm passing the button's ClientID to the script itself
within the Page_Init-event as well, I guess this should really be working,
but obviously it doesn't ...

Cheers,
Olaf
--
My .02: www.Resources.IntuiDev.com
Nov 18 '06 #12
"Olaf Rabbachin" <Ol*********@IntuiDev.comwrote in message
news:eg**************@TK2MSFTNGP06.phx.gbl...
I do, but still, the dynamic checkboxes won't show the ID rather than the
ClientID. Since I'm passing the button's ClientID to the script itself
within the Page_Init-event as well, I guess this should really be working,
but obviously it doesn't ...
In which case, don't pass the ClientID at all, as follows:

If Not ClientScript.IsClientScriptBlockRegistered("Enable Go") Then
Dim strJS As String = _
"<script language=""JavaScript""" & _
"function enableGo(chk) {" & _
"document.getElementById(""" & cmdGo.ClientID & """).disabled = " & _
"chk.checked == false);" & _
"}" & _
"</script>"
ClientScript.RegisterClientScriptBlock(Me.GetType, "EnableGo", strJS)
End If

chkBox.Attributes.Add("onclick", "enableGo(this);")
Nov 18 '06 #13
Hi,

Mark Rae wrote:
>I do, but still, the dynamic checkboxes won't show the ID rather than the
ClientID. Since I'm passing the button's ClientID to the script itself
within the Page_Init-event as well, I guess this should really be working,
but obviously it doesn't ...

In which case, don't pass the ClientID at all, as follows:

If Not ClientScript.IsClientScriptBlockRegistered("Enable Go") Then
Dim strJS As String = _
"<script language=""JavaScript""" & _
"function enableGo(chk) {" & _
"document.getElementById(""" & cmdGo.ClientID & """).disabled = " & _
"chk.checked == false);" & _
"}" & _
"</script>"
ClientScript.RegisterClientScriptBlock(Me.GetType, "EnableGo", strJS)
End If

chkBox.Attributes.Add("onclick", "enableGo(this);")
might be another way, I'll try that out. However, the reason for my code
not working seems to have been that the dynamic checkboxes themselves were
part of dynamic table-cells. The ClientID seems to be created only after
controls (that is, the top-container they may be part of) are actually
being added to the page. In my case, the ClientID will be right after the
table-cell - being the checkbox's parent - will have been added to the
page. Et voilá!

Cheers & thanks again,
Olaf
--
My .02: www.Resources.IntuiDev.com
Nov 18 '06 #14

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

Similar topics

20
by: Jeff Nibler | last post by:
I'm trying to set the width of a textbox via a style sheet but it isn't working for Netscape 4.7 This is what the page looks like: <form> <input type="text" class="t1"> </form> This is...
16
by: Ramsin Savra | last post by:
Hi, What do you suggest to do if I want to do a search in TextBox ? I know that using RichTextBox, we could have Find method to search for a specific word or information but I was wonder if...
7
by: Drew Berkemeyer | last post by:
I've encounted a pretty strange problem and I'm not quite sure what to make of it. I have a web service that consumes an XML file as well as a few other parameters. This web service works fine...
7
by: BobRoyAce | last post by:
Let's say I have a text box on a page in which a user is to enter a monetary amount and that I want to ensure that the user enters a value greater than or equal to a certain value that will be...
2
by: hemant | last post by:
hello everybody, I am having a datagrid which has data regarding customers. it has a penalty column, and i want to show the entire record of the customer in red whose penalty is greater than...
14
by: MLH | last post by:
I use A97. I've gotten used to reading values from textbox controls on forms, I've come to rely on it pretty heavily. My habit spills over into reports. I'm uncertain whether I can reliably read...
2
by: simon | last post by:
hello, new to vb.net, have a few questions about DataGrid. I have a dataGrid that is working pulling a dataset back from a stored proc and binding to the datagrid for display the datagrid's...
2
by: Luqman | last post by:
I have coded in Textbox_changed Event: If CType(txtVoucherNo.Text, Long) = 0 Then Me.DetailsView1.ChangeMode(DetailsViewMode.Insert) Me.DetailsView1.AutoGenerateInsertButton = True ...
5
by: =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?= | last post by:
I'm sorry, but I've read your code a couple of times and just don't see where the Form1 is initialized. Form1 also sounds like a class name, and this would be how you could do some form operations...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.