473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Javascript function called from code behind file

Hi..

I am trying to use javascript for google maps display.
If I call the javascript function from my aspx file I use:
<input type="text" id="addresstext" value="Huntington Avenue,
Boston, MA" name="yourName" style="width: 287px" />
<input type="button" id="addressclick" value="Display Map"
onclick="showAddress(addresstext.value)" /><br />
and it works.
But using the Response.Write from the aspx.cs file it
does not display it. I need to pass an argument to the function
call.Am I passing the value wrongly??
I am calling it this way:
Response.Write("<script
language='javascript'>showAddress("+getAddress+"); </script>");
where, getAddress is the comma-seperated Address string.
This is not displaying the map, I am creating using Javascript.

I have also tried all combinations of singel quotes, and double quotes
wrt calling the javascript function
Thx

Apr 11 '07 #1
3 21729
Most likely that Response.Write has rendered your JavaScript block outside
HTML-tag.
Best way to add JavaScripts from codebehind is to use
RegisterClientScriptBlock

this.RegisterClientScriptBlock("jsGoogleMap","<scr ipt
language='javascript'>showAddress("+getAddress+"</script>");


"moni" wrote:
Hi..

I am trying to use javascript for google maps display.
If I call the javascript function from my aspx file I use:
<input type="text" id="addresstext" value="Huntington Avenue,
Boston, MA" name="yourName" style="width: 287px" />
<input type="button" id="addressclick" value="Display Map"
onclick="showAddress(addresstext.value)" /><br />
and it works.
But using the Response.Write from the aspx.cs file it
does not display it. I need to pass an argument to the function
call.Am I passing the value wrongly??
I am calling it this way:
Response.Write("<script
language='javascript'>showAddress("+getAddress+"); </script>");
where, getAddress is the comma-seperated Address string.
This is not displaying the map, I am creating using Javascript.

I have also tried all combinations of singel quotes, and double quotes
wrt calling the javascript function
Thx

Apr 12 '07 #2
Oh....yeah, don't inject javascript into your ASPX page using
Response.Write, there are much better methods for doing this. Have a look at
RegisterStartupScript, etc. Those are going to work with your ASP.net page
infrastructure. What you're doing is going to place script *outside* HTML
blocks and will probably never work - and if it does, it's by chance.

--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/blog
"moni" <mo*******@gmail.comwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
Hi..

I am trying to use javascript for google maps display.
If I call the javascript function from my aspx file I use:
<input type="text" id="addresstext" value="Huntington Avenue,
Boston, MA" name="yourName" style="width: 287px" />
<input type="button" id="addressclick" value="Display Map"
onclick="showAddress(addresstext.value)" /><br />
and it works.
But using the Response.Write from the aspx.cs file it
does not display it. I need to pass an argument to the function
call.Am I passing the value wrongly??
I am calling it this way:
Response.Write("<script
language='javascript'>showAddress("+getAddress+"); </script>");
where, getAddress is the comma-seperated Address string.
This is not displaying the map, I am creating using Javascript.

I have also tried all combinations of singel quotes, and double quotes
wrt calling the javascript function
Thx

Apr 12 '07 #3
Note that in ASP.Net 2.0, this method (and related) has been superceded by
the ClientScriptManager's methods for doing the same things. The
ClientScriptManager is a property of the System.Web.UI.Page class, and is
exposed in the Page.ClientScript property. See:

http://msdn2.microsoft.com/en-us/lib...pt(VS.80).aspx
http://msdn2.microsoft.com/en-us/lib...ptmanager.aspx

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Jouni Karppinen" <Jo************@discussions.microsoft.comwrote in
message news:20**********************************@microsof t.com...
Most likely that Response.Write has rendered your JavaScript block outside
HTML-tag.
Best way to add JavaScripts from codebehind is to use
RegisterClientScriptBlock

this.RegisterClientScriptBlock("jsGoogleMap","<scr ipt
>language='javascript'>showAddress("+getAddress+ "</script>");

"moni" wrote:
>Hi..

I am trying to use javascript for google maps display.
If I call the javascript function from my aspx file I use:
<input type="text" id="addresstext" value="Huntington Avenue,
Boston, MA" name="yourName" style="width: 287px" />
<input type="button" id="addressclick" value="Display Map"
onclick="showAddress(addresstext.value)" /><br />
and it works.
But using the Response.Write from the aspx.cs file it
does not display it. I need to pass an argument to the function
call.Am I passing the value wrongly??
I am calling it this way:
Response.Write("<script
language='javascript'>showAddress("+getAddress+") ;</script>");
where, getAddress is the comma-seperated Address string.
This is not displaying the map, I am creating using Javascript.

I have also tried all combinations of singel quotes, and double quotes
wrt calling the javascript function
Thx


Apr 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Arthur Connor | last post by:
Is there a way of extracting the Javascript code from the "normal" HTML code (e.g. similar to CSS code which can be put into a separate file) ? If you offer a solution: can I determine in your...
4
by: Steven | last post by:
Hello, I have 3 files -- 1. mainform.aspx 2. mainform.aspx.cs 3. mouse.js mainform.aspx contains a image button ("zoominimgbut") which will exceute C# code, whenever the user clicks on it....
8
by: Maverick | last post by:
I want to group all the javascript functions into a file named MiscFunc.js in a asp.net project. ======================================== e.g. In MiscFunc.js function dummyFunc(var1, var2) {...
3
by: anadimpa | last post by:
Hello all I build a javascript function string in the code behind and register it in the Page_Load of my User Control. I do this because I build the javascript based on some variables that are...
8
by: Frank | last post by:
Hi, I am working with VS.NET 2005 Ultimately, I wish to call a JavaScript function from a .js file
4
by: verci | last post by:
Hi guys, I'm running asp.net 2.0. Does anyone know how to fire or call a javascript function from inside my (VB.aspx) code without assigning it to a control attribute? thank you
4
by: sajithkahawatta | last post by:
i want to call a java script function from code behind. in page1.aspx page i placed script' <script language="javascript"> function SetSelected() { infoTextBox.select(); } </script>
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
2
by: Matthew Wells | last post by:
Hello. I thought this was supposed to be simple. I'm trying to use a .js file for my javascript functions. I'm testing by only using one function The function works when it's at the top of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.