473,473 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Question on ASP .NET page Javascript

Hi,

I am binding the button.text dynamicall depending on the selection value of
the dropdownlist, at the same time I am trying to use a javascript to alert
users, but it does not fire. This is how I am doing it

In the page_load event I do this:
btnView.Attributes.Add("onclick", "return
TestValidator(btnView.Text);");

and in the page I do this:
function TestValidator(buttonValue)
{
if (buttonValue == "Get Name Values")
{
if (document.forms[0].FirstName.value != '' &&
document.forms[0].LastName.value != '')
{
var x = window.confirm("The Results will be according to LastName, do you
wish to proceed?")
return (x);
}
}
else if (buttonValue == "Get All Values")
{
if (document.forms[0].EmpID.value == '' || document.forms[0].Address.value
== '' || document.forms[0].Department.value == '')
{
alert("Requires EmpID, Address and Department")
}
}
}

Please Advice.
Stephen

[p.s: I apologize if I have posted in the wrong group]
Dec 7 '06 #1
2 967
"stephen" <st********@hotmail.comwrote in message
news:e8**************@TK2MSFTNGP05.phx.gbl...
but it does not fire
Are you absolutely sure...? Place an alert at the very beginning of the
JavaScript function and see if it pops up...
In the page_load event I do this:
btnView.Attributes.Add("onclick", "return
TestValidator(btnView.Text);");
Has that actually worked? When the page has loaded, do a View Source and
check that the attribute has been correctly added to the button.
Dec 7 '06 #2
you have a couple errors.

1) on client side, buttons do not have a .Text property. so the if will
never be true. if is a button, you want the value.

2) in the onclick attribute you are referencing the button by name
instead of using document.getElementById or by form as in the code. but
as a on click handler you can just:

btnView.Attributes.Add("onclick",
"return TestValidator(this.value);");

3. you are using the asp.net control ids, to access elements, which may
not be what is rendered. try:

var v = document.forms[0].<%=EmpID.ClientID%>.value;

-- bruce (sqlwork.com)

stephen wrote:
Hi,

I am binding the button.text dynamicall depending on the selection value of
the dropdownlist, at the same time I am trying to use a javascript to alert
users, but it does not fire. This is how I am doing it

In the page_load event I do this:
btnView.Attributes.Add("onclick", "return
TestValidator(btnView.Text);");

and in the page I do this:
function TestValidator(buttonValue)
{
if (buttonValue == "Get Name Values")
{
if (document.forms[0].FirstName.value != '' &&
document.forms[0].LastName.value != '')
{
var x = window.confirm("The Results will be according to LastName, do you
wish to proceed?")
return (x);
}
}
else if (buttonValue == "Get All Values")
{
if (document.forms[0].EmpID.value == '' || document.forms[0].Address.value
== '' || document.forms[0].Department.value == '')
{
alert("Requires EmpID, Address and Department")
}
}
}

Please Advice.
Stephen

[p.s: I apologize if I have posted in the wrong group]

Dec 7 '06 #3

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

Similar topics

5
by: Al Davis | last post by:
Note: I tried cross-posting this message to several newsgoups, including comp.lang.perl.misc, c.l.p.moderated, comp.infosystems.www.authoring.cgi, comp.lang.javascript and comp.lang.php. Nothing...
3
by: Randell D. | last post by:
Folks, I'm still learning javascript - I've invested in a couple of books and reading online as much as possible. I'm pretty sure what I am suggesting is possible though I'm trying to weigh up...
2
by: Mark Preston | last post by:
Its perhaps a bit early to ask, since I'm still doing the page design and haven't got down to the coding yet, but I wonder if anyone can help with a bit of a question. To lay the groundwork, a...
33
by: Nigel Molesworth | last post by:
I've Googled, but can't find what I need, perhaps I asking the wrong question! I want a "FAQ" page on a web site, I hate those pages that scroll you to the answer so and I figured that a good...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
7
by: e | last post by:
I've been having an extremely difficult time finding an answer to this in IE / js groups, so I thought I'd try here. I've got an aspx page that delivers loads of report data into custom-named...
6
by: David | last post by:
I am running into situtations where confining all forms to just one window (instance of broswer) is becoming overly restrictive. Does ASP.NET provide ways to have multiple windows to interact with...
6
by: Ashok | last post by:
Hi, I am starting a new project to build a software product using APS.NET 2.0. In past I have used "frameset" and "frame" to build pages. My current requirements I have coded using frameset and...
25
by: eggie5 | last post by:
I have a form where a user can change his password, but I'm confused on how to prevent this from being transmitted in plain text. Well, I know how not to transmit it in plain text - use any type...
25
by: bweaverusenet | last post by:
Hi. I am trying to get some javascript to work in IE6, from the address line. It works in Firefox and, I believe, IE7. It appears that with some number of nested structures, the code does not...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.