|
 |
aspx thread: Call a JavaScript function in Aspx page
Message #1 by "nima" <neonima@y...> on Tue, 7 Jan 2003 00:36:17
|
|
Hi
I wrote some functions in a separate javascript file. (for example
test.js) I currently included it in my HTML page and using functions when
certain html elements trigger certain events (click,focus,etc).
But I also need to use them in a Aspx page I mean for example in Click
event of server side button.
But I can not include the javascript file in my aspx page ( I dont know
how to add a refrence of file to page in VB.NET )
Any insight is greatly appreciated.
Message #2 by "Greg Quinn" <greg@i...> on Tue, 7 Jan 2003 00:55:23 -0800
|
|
After your server side script tags, putting in the usual source fuile
declaration will work...
i.e
<script language = "vb" runat = "server">
Sub Page_Load()
End Sub
</script>
<script language = "JavaScript" src = "../scripts/myscripts.js"></script>
Then when the page is requested from the server, you will still be able to
access any of the functions in the .js source file.
-----Original Message-----
From: nima [mailto:neonima@y...]
Sent: Tuesday, January 07, 2003 12:36 AM
To: ASP.NET
Subject: [aspx] Call a JavaScript function in Aspx page
Hi
I wrote some functions in a separate javascript file. (for example
test.js) I currently included it in my HTML page and using functions when
certain html elements trigger certain events (click,focus,etc).
But I also need to use them in a Aspx page I mean for example in Click
event of server side button.
But I can not include the javascript file in my aspx page ( I dont know
how to add a refrence of file to page in VB.NET )
Any insight is greatly appreciated.
Message #3 by "nima" <neonima@y...> on Tue, 7 Jan 2003 17:41:28
|
|
Thank you Greg
But as I am a newbie in asp.net I am a little confused
I have a JavaScript function named Myfunction which it returns a string as
result and is in myscripts.js can I use it like this in .NET ?
<script language = "vb" runat = "server">
Sub Page_Load()
text1.text=MyFunction
End Sub
</script>
<script language = "JavaScript" src = "../scripts/myscripts.js"></script>
Message #4 by "Rodney Majola" <MajolaR@a...> on Wed, 8 Jan 2003 09:37:15 +0200
|
|
Hi nima
It looks like the script u're trying to execute is a client script and
u're trying to call it from your server side logic. To solve the
problem, I suggest that u convert your functions to c# or a .Net version
of JScript.
Remember your script woll need to have a runat=3DServer attribute at the
top.
-----Original Message-----
From: nima [mailto:neonima@y...]
Sent: 07 January 2003 07:41 PM
To: ASP.NET
Subject: [aspx] RE: Call a JavaScript function in Aspx page
Thank you Greg
But as I am a newbie in asp.net I am a little confused
I have a JavaScript function named Myfunction which it returns a string
as
result and is in myscripts.js can I use it like this in .NET ?
<script language =3D "vb" runat =3D "server">
Sub Page_Load()
text1.text=3DMyFunction
End Sub
</script>
<script language =3D "JavaScript" src =3D
"../scripts/myscripts.js"></script>
Message #5 by "Greg Quinn" <greg@i...> on Wed, 8 Jan 2003 01:34:39 -0800
|
|
Nima,
Remember that JavaScript is a client-side language and that asp.net is a
server side language. So the two cannot talk directly to each other.
The best way to pass a value between server-side and client-side is to use
hidden form fields.
I'm not sure what you're trying to do, but if you just want to populate a
textbox with a javascript value when the page loads, why not just use the
following method?
<script language = "JavaScript">
function fillBox()
{
document.myForm.text1.value
}
</script>
<body onLoad = "fillBox();">
Or if you need a javascript value that you need to incorporate into your
asp.net server-side code, try something like this...
<script language = "vb" runat = "server">
Sub Page_Load()
Dim jScriptString as String
jScriptString = "<SCR" + "IPT>"
jScriptString += "myJavaScriptValue = myFunction();"
jScriptString += "document.myForm.text1.value = myJavaScriptValue;"
jScriptString += "</SCR" + "IPT>"
End Sub
</script>
<script language = "JavaScript" src = "../scripts/myscripts.js"></script>
<html>
<form id = "myForm" runat = "server">
<asp:textbox id = "text1" runat = "server" />
</form>
</html>
-----Original Message-----
From: nima [mailto:neonima@y...]
Sent: Tuesday, January 07, 2003 5:41 PM
To: ASP.NET
Subject: [aspx] RE: Call a JavaScript function in Aspx page
Thank you Greg
But as I am a newbie in asp.net I am a little confused
I have a JavaScript function named Myfunction which it returns a string as
result and is in myscripts.js can I use it like this in .NET ?
<script language = "vb" runat = "server">
Sub Page_Load()
text1.text=MyFunction
End Sub
</script>
<script language = "JavaScript" src = "../scripts/myscripts.js"></script>
Message #6 by "nima" <neonima@y...> on Wed, 8 Jan 2003 10:44:09
|
|
Hi Greg
I have a WYSIWYG editor editor.js file it works fine in a HTML page and it
have to function on named SetText and one GetText to set and get the text
of editor, now I want to use the editor in asp.NET in visual studio , I
mean I am trying to make it a user control and use those two functions to
get and set the text of to Database in VB Code Behind, I can send the
source of editor.
Message #7 by "Greg Quinn" <greg@i...> on Wed, 8 Jan 2003 04:05:15 -0800
|
|
Sorry, but I don't use vs.net
Do you have a HTML text editor on your page? Is the page an Iframe that lets
you edit the content?
I have done this before, so if you give me the javascript method of
inserting text into the editor, I can show you how to insert database text.
Otherwise what I did before was I would set the text of a hidden field with
my asp.net code...
i.e
Sub Page_Load()
hidText.Value = "This is the text from the database"
End Sub
Then I will set the text of the HTML editor by using javascript...
function setEditorText()
{
document.editorText.value = document.hidText.value
}
<body onLoad = "setEditorText();">
Greg
-----Original Message-----
From: nima [mailto:neonima@y...]
Sent: Wednesday, January 08, 2003 10:44 AM
To: ASP.NET
Subject: [aspx] RE: Call a JavaScript function in Aspx page
Hi Greg
I have a WYSIWYG editor editor.js file it works fine in a HTML page and it
have to function on named SetText and one GetText to set and get the text
of editor, now I want to use the editor in asp.NET in visual studio , I
mean I am trying to make it a user control and use those two functions to
get and set the text of to Database in VB Code Behind, I can send the
source of editor.
|
|
 |