|
 |
aspx thread: javascript from asp.net
Message #1 by "Bob Piric" <bpiric@l...> on Tue, 20 Aug 2002 17:31:13
|
|
Hi there,
Well I know I was able to do something like
Response.Write "<script>alert('Your search did not return any
records!');</script>"
from my asp page in Visual Interdev. Now I'm using .NET and this still
works but how do I call custom-made javascript function, which is in my
html part of page from code behind? I tried something like
Response.Write("<script language='javascript'>ShowHide('NewError')
</script>")
but it gives me an error something like object required.
Thanks a lot guys!
Message #2 by "Lindahl, Ron" <Ron.Lindahl@L...> on Tue, 20 Aug 2002 13:32:52 -0400
|
|
Bob-
I found one way of handling this.
I created a function in the code behind page which returns a string
containing the script tags and all the script code.
In the HTML page I coded
<%=functionName%>
where I wanted the script to be in the HTML.
If someone knows a way to handle to this without the old school ASP tag, I'd
be interested as well.
-----Original Message-----
From: Bob Piric [mailto:bpiric@l...]
Sent: Tuesday, August 20, 2002 1:31 PM
To: ASP+
Subject: [aspx] javascript from asp.net
Hi there,
Well I know I was able to do something like
Response.Write "<script>alert('Your search did not return any
records!');</script>"
from my asp page in Visual Interdev. Now I'm using .NET and this still
works but how do I call custom-made javascript function, which is in my
html part of page from code behind? I tried something like
Response.Write("<script language='javascript'>ShowHide('NewError')
</script>")
but it gives me an error something like object required.
Thanks a lot guys!
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #3 by "Dave Rezoski" <daverezoski@h...> on Tue, 20 Aug 2002 22:20:27 +0000
|
|
one way to do it is to use a LiteralControl.
I'm not sure *exactly* what you're asking, but in the past I've placed an
<asp:PlaceHolder> on the page, then added a control (in this case a button
that fires off javascript) to the placeholder from the codebehind, at
runtime.
in the aspx page:
<asp:PlaceHolder Runat=server Visible=False ID=phBtnClose></asp:PlaceHolder>
in the C# code behind:
//declare your placeholder
protected System.Web.UI.WebControls.PlaceHolder phBtnClose;
//add anything you want into the placeholder... in this case, a button.
phBtnClose.Controls.Add(new LiteralControl("<input type=button value='close
window' onClick='javascript: CloseWindow();' class=smButton>"));
basically, the codebehind renders a button on the client side - the button
click event references javascript that is already on the client side.
make sense? did this help?
----Original Message Follows----
From: "Lindahl, Ron" <Ron.Lindahl@L...>
Reply-To: "ASP+" <aspx@p...>
To: "ASP+" <aspx@p...>
Subject: [aspx] RE: javascript from asp.net
Date: Tue, 20 Aug 2002 13:32:52 -0400
Bob-
I found one way of handling this.
I created a function in the code behind page which returns a string
containing the script tags and all the script code.
In the HTML page I coded
<%=functionName%>
where I wanted the script to be in the HTML.
If someone knows a way to handle to this without the old school ASP tag, I'd
be interested as well.
-----Original Message-----
From: Bob Piric [mailto:bpiric@l...]
Sent: Tuesday, August 20, 2002 1:31 PM
To: ASP+
Subject: [aspx] javascript from asp.net
Hi there,
Well I know I was able to do something like
Response.Write "<script>alert('Your search did not return any
records!');</script>"
from my asp page in Visual Interdev. Now I'm using .NET and this still
works but how do I call custom-made javascript function, which is in my
html part of page from code behind? I tried something like
Response.Write("<script language='javascript'>ShowHide('NewError')
</script>")
but it gives me an error something like object required.
Thanks a lot guys!
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
Message #4 by "John Wormald" <johnswormald@h...> on Wed, 21 Aug 2002 10:50:10
|
|
Bob
You may also want to consider using the classes,
Page.RegisterClientScriptBlock and Page.RegisterStartupScript to create
client side javascript. There are good examples at:
http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=438
and
http://www.dotnetbips.com/displayarticle.aspx?id=106
Good luck
John
> Hi there,
W> ell I know I was able to do something like
R> esponse.Write "<script>alert('Your search did not return any
r> ecords!');</script>"
f> rom my asp page in Visual Interdev. Now I'm using .NET and this still
w> orks but how do I call custom-made javascript function, which is in my
h> tml part of page from code behind? I tried something like
R> esponse.Write("<script language='javascript'>ShowHide('NewError')
<> /script>")
b> ut it gives me an error something like object required.
T> hanks a lot guys!
Message #5 by "Lindahl, Ron" <Ron.Lindahl@L...> on Wed, 21 Aug 2002 10:47:54 -0400
|
|
John,
I can't speak for Bob, but thanks.
One more step in my rehabilitation from old school ASP tags...
Ron
-----Original Message-----
From: John Wormald [mailto:johnswormald@h...]
Sent: Wednesday, August 21, 2002 6:50 AM
To: ASP+
Subject: [aspx] Re: javascript from asp.net
Bob
You may also want to consider using the classes,
Page.RegisterClientScriptBlock and Page.RegisterStartupScript to create
client side javascript. There are good examples at:
http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=438
and
http://www.dotnetbips.com/displayarticle.aspx?id=106
Good luck
John
> Hi there,
W> ell I know I was able to do something like
R> esponse.Write "<script>alert('Your search did not return any
r> ecords!');</script>"
f> rom my asp page in Visual Interdev. Now I'm using .NET and this still
w> orks but how do I call custom-made javascript function, which is in my
h> tml part of page from code behind? I tried something like
R> esponse.Write("<script language='javascript'>ShowHide('NewError')
<> /script>")
b> ut it gives me an error something like object required.
T> hanks a lot guys!
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #6 by mark_greenberg@l... on Wed, 21 Aug 2002 18:41:45
|
|
Check out these examples.
http://www.aspalliance.com/aldotnet/examples/cd.aspx
They show how to pop up a javascript confirmation window from an ASP.NET
DataGrid control.
> Hi there,
W> ell I know I was able to do something like
R> esponse.Write "<script>alert('Your search did not return any
r> ecords!');</script>"
f> rom my asp page in Visual Interdev. Now I'm using .NET and this still
w> orks but how do I call custom-made javascript function, which is in my
h> tml part of page from code behind? I tried something like
R> esponse.Write("<script language='javascript'>ShowHide('NewError')
<> /script>")
b> ut it gives me an error something like object required.
T> hanks a lot guys!
Message #7 by "Bob Piric" <bpiric@l...> on Thu, 22 Aug 2002 14:04:50
|
|
I want to thank you all for you replays. John's suggestion worked for me
and I think it's the most elegant and proper way of doing it. Once again
thanks a bunch guys!
Cheers,
Bob
|
|
 |