By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,483 Members | 3,312 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,483 IT Pros & Developers. It's quick & easy.

javascript functions not working on asp.net page

100+
P: 233
I have a page that contain input form, a contact us page. I also have a few javascript functions, one in particular sends the visitor back to the home page.

My javascript is not functioning properly, the user is supposed to be directed back to the home page, but instead the page simply seems to reload. I would assume that the form is trying to post back, however, I would like to avoid this if possible. In the past for other asp.net button, I could add:

if (!Page.IsPostBack)
{
code here...
}

Is there a similar work around for javascript functions?
Jan 15 '08 #1
Share this Question
Share on Google+
6 Replies


100+
P: 233
I suppose there could be a different issue here. Has anyone at least heard of this type of thing happening previously. To simplify:

-1 .aspx page
-1 contact us form with submit button that initiates method of sending the user input as an email
-1 HTML input of type image that when click is supposed to initiate javascript funtion home(), but does not work properly and instead seems to reload the page.
Jan 15 '08 #2

acoder
Expert Mod 15k+
P: 16,027
Show your JavaScript code.
Jan 16 '08 #3

100+
P: 233
Show your JavaScript code.
Brace yourself,

function navURL(url) {
window.location.href = url;
}
Jan 16 '08 #4

acoder
Expert Mod 15k+
P: 16,027
OK, so how do you call this code?
Jan 16 '08 #5

100+
P: 233
OK, so how do you call this code?
<input type=image src="Images/QuikeyGreenLogoOnGREENfield.gif" onClick="navURL('http://www.physicaladvertising.com');return false;" />

Previously I did not have return false;. The function now operates properly.

On another note, on this same page, when the submit button is clicked, a c# method is called, I would like to call a different javascript function from that method if possible. Essentially the c# method sends the contents of the contact us page in an email, upon doing so I would like to call a javascript function that grays out the background and makes a div tag present. Can javascript be called from server side controls?
Jan 16 '08 #6

acoder
Expert Mod 15k+
P: 16,027
Previously I did not have return false;. The function now operates properly.
Yes, that should solve it and has.
On another note, on this same page, when the submit button is clicked, a c# method is called, I would like to call a different javascript function from that method if possible. Essentially the c# method sends the contents of the contact us page in an email, upon doing so I would like to call a javascript function that grays out the background and makes a div tag present. Can javascript be called from server side controls?
Just output the JavaScript from the server-side code to be run when the page loads.
Jan 16 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.