|
-
Jan 19th, 2005, 12:40 PM
#1
Thread Starter
Frenzied Member
JS and ASP.net
I have a button in my user control:
<asp:Button ID=si Text=SI Runat=server cssclass=knap Enabled=False Width=50px OnClick="openNewWindow"></asp:Button>
And the js-function is defined at the beginning of the ascx-file:
<script language=javascript type="text/javascript">
function openNewWindow()
{
var winName = "w";
var winURL = "gf2004.aspx";
var w;
w = window.open(winURL,winName);
w.focus();
}
</script>
I have two questions:
1) Why does this code not work? Has it something to do with the user control? The error message is:
Compiler Error Message: BC30456: 'openNewWindow' is not a member of 'ASP.Buttons_ascx'.
2) Is it possible in JS to use this url winURL = "gf2004.aspx"; when the path is the same? Or do I have to use absolute paths (not preferred!)
-
Jan 19th, 2005, 01:10 PM
#2
Addicted Member
Re: JS and ASP.net
not sure if i'm right here, but for your question 1 I remember that user controls do not have a form tag, and JS needs a form tag to work. Could be wrong, search it on google :/
-
Jan 19th, 2005, 09:06 PM
#3
Re: JS and ASP.net
This:
OnClick="openNewWindow();"
should work.
If it doesn't, post back, I'll show you another way of doing this.
-
Jan 21st, 2005, 01:38 PM
#4
Frenzied Member
Re: JS and ASP.net
Yeah you have to put the () the ; is optional.
Magiaus
If I helped give me some points.
-
Jan 21st, 2005, 10:23 PM
#5
Re: JS and ASP.net
 Originally Posted by Magiaus
Yeah you have to put the () the ; is optional.
I've had a few problems when I didn't include that, especially when the button's onClick event contains other javascript function put in there by ASP.NET, so it's best practice to include it, although as you said, optional.
-
Jan 22nd, 2005, 04:36 AM
#6
Thread Starter
Frenzied Member
Re: JS and ASP.net
 Originally Posted by Patch21
not sure if i'm right here, but for your question 1 I remember that user controls do not have a form tag, and JS needs a form tag to work. Could be wrong, search it on google :/
Now I have tried to include "openNewWindow();", but it doesn't make any change. I think it has something to do with the user control then. How can I implement js in a user control? Does the js-code need to be in the aspx-file, which includes the user control or...?
-
Feb 7th, 2005, 08:02 AM
#7
Fanatic Member
Re: JS and ASP.net
VB Code:
Button1.Attributes.Add("onClick", "openNewWindow()")
-
Feb 7th, 2005, 08:53 AM
#8
Frenzied Member
Re: JS and ASP.net
 Originally Posted by mendhak
I've had a few problems when I didn't include that, especially when the button's onClick event contains other javascript function put in there by ASP.NET, so it's best practice to include it, although as you said, optional.
I know what you mean. Have you ever had it not work in a browser because of the ;? I have. I try to use a function if I got more than on statement. It was like NN4 I think....
Magiaus
If I helped give me some points.
-
Feb 8th, 2005, 04:43 AM
#9
Re: JS and ASP.net
That just makes me glad I don't touch NN. In fact, it's been years since I've seen anyone using NN!
-
Feb 8th, 2005, 05:56 PM
#10
New Member
Re: JS and ASP.net
Strider is right!
Your button runs on the server and openNewWindow() is considered to be code that runs on the server. That's why it cannot be found.
Remove the onClick="openNewWindow()" in your HTML tag and put the line and add the line of code Strider posted in you code behind page_load event.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|