Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript and VB.NET events

Status
Not open for further replies.

Peppi

Programmer
Apr 9, 2001
205
CA
Hi,

I tried posting this problem in the ASP.NET forum but didn't really have any luck there.

I've attached some JavaScript code to the onChange event of a textbox that will check if a valid date has been entered. If the date is valid, then I want the corresponding VB.NET OnTextChanged event to be called. I'd thought that simply having my JavaScript return either 'true' or 'false' would handle this, but it turns out that my VB.NET event never gets called. It only seems to work if I remove the 'return' statements, which I don't want to do as I only want the OnTextChanged event to run if it's a valid date.

Here is the relevant code:

Code:
leaveDateTextBox.Attributes.Add("onChange", "if (verifyDate(" + leaveDateTextBox.ClientID + ")) {flagAsChanged(" + rowChangedHiddenField.ClientID + "); return true;} else {return false;}")

Thx.
 
Peppi, you really should post the javascript code from the generated HTML source. It's hard to tell you what the page is doing if you don't post code that the page sees. The code posted above is what ASP.Net sees before it decides what to send to the browser.

Now, that said..... are you sure that you are wanting to fire off a VB.Net function when the value is changed in the dropdown? All the VB.Net functions are going to reside on the server, and since changing the dropdown value is a client-side event it can't trigger a server side function w/o either submitting the form or some sort of AJAX trick.

Please post some client-generated javascript and HTML and we should be able to get you pointed in the right direction.

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
OK, here's a sample of the javascript from the HTML for one of the textboxes:

Code:
<input name="ctl00$Main$grdVacation$ctl04$txtLeaveDate" type="text" value="2007/03/05 12:00:00 AM" onchange="if (verifyDate(ctl00_Main_grdVacation_ctl04_txtLeaveDate)) {flagAsChanged(ctl00_Main_grdVacation_ctl04_RowChanged); return true;} else {return false;};setTimeout('__doPostBack(\'ctl00$Main$grdVacation$ctl04$txtLeaveDate\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="ctl00_Main_grdVacation_ctl04_txtLeaveDate" style="font-size:10px;width:64px;" />

I am actually talking about a text box here and not a drop-down. I have two date text boxes. What I'm essentially trying to do is, once either of the dates has changed, to re-calculate and re-display the number of business days between those two dates. This work is taking place within an AJAX UpdatePanel, so the whole page will not have to refresh.

Any insight you may have is appreciated.
 
I'd guess that you're missing some single quotation marks.
Code:
if (verifyDate([b][red]'[/red][/b]ctl00_Main_grdVacation_ctl04_txtLeaveDate[b][red]'[/red][/b])) {flagAsChanged([b][red]'[/red][/b]ctl00_Main_grdVacation_ctl04_RowChanged[b][red]'[/red][/b]);

Without seeing the actual functions referred to, though, it's difficult to tell.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top