Hello everybody,
I know it is an ordinary question, I tried a lot and searched but got nothing.
I request another page (Default2.aspx) using JavaScript from (Default.aspx), get a response Response.Write() as a JavaScript then using document.write() to update the page. - <script language="javascript" type="text/javascript">
-
var xmlHttpTopologyReceiver = GetXmlHttpObject();
-
function GetXmlHttpObject()
-
{
-
var xmlHttp = null;
-
try
-
{
-
// Firefox, Opera 8.0+, Safari
-
xmlHttp = new XMLHttpRequest();
-
}
-
catch (e)
-
{
-
// Internet Explorer
-
try
-
{
-
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch (e)
-
{
-
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
}
-
return xmlHttp;
-
}
-
function receiveData()
-
{
-
if(null == xmlHttpTopologyReceiver)
-
{
-
alert("Your browser does not support AJAX!");
-
return;
-
}
-
-
var url = "Default2.aspx";
-
-
xmlHttpTopologyReceiver.onreadystatechange = stateChanged;
-
xmlHttpTopologyReceiver.open("GET", url, true);
-
xmlHttpTopologyReceiver.send(null);
-
}
-
-
function hola()
-
{
-
alert('Hola');
-
}
-
-
function stateChanged()
-
{
-
if (xmlHttpTopologyReceiver.readyState == 4)
-
{
-
var data = xmlHttpTopologyReceiver.responseText;
-
-
document.write(data);
-
}
-
}
-
</script>
code of Default2.aspx - protected void Page_Load(object sender, EventArgs e)
-
{
-
Response.Write("<script language=\"javascript\" type=\"text/javascript\">alert('Hello');</script>");
-
}
The problem is when I replace alert('Hello'); with hola(); it does not execute.
Any help please! Thanks
6 20493
Two problems:
1. Don't use document.write after the page has finished loading, otherwise it will overwrite the already loaded page.
2. When requesting JavaScript code, you need to either eval it or dynamically include via script tags (by adding to the head).
Thanks a lot acoder for reply.
Thanks for correcting me. I've simple question if you have a time.
1. What other possibility can I do instead of document.write() ?
2. I didn't understand well what you meant but I'm going t read about eval more, please if you can guide me with simple link in that.
Thanks,
Bassem
Well I just read a simple implement to eval function I'm out of my PC now but I hope it will work for me, the problem as you helped me is document.write() and I don''t know another way to implement.
I'll try more.
1. so-called DOM scripting (manipulating the document tree by methods of the DOM API). a good starting point is MDC
2. to execute Javascript code it has to be parsed by the browser beforehand (which is done on page load) any Javascript inserted later is not parsed and thus not available by default.
Thanks a lot Dormilich.
I know my questions were so basic, but I'm getting my first steps and so lost.
I'll follow the link.
Thank you
@Bassem
eval() is not the only option. If you're sure exactly what code will be produced, then eval might be ok, but if not, it could be dangerous. As I mentioned, you can also include the code using script tags dynamically, e.g.: - var script = document.createElement("script");
-
script.type = ...
-
script.appendChild(document.createTextNode(theCode);
-
document.getElementsByTagName("head")[0].appendChild(script);
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matthew Wieder |
last post by:
On my Page_Load event, i need to do some validation and then either let
them proceed, or display a error message and boot them back to the
previous page. Here is the code:
...
|
by: Paul |
last post by:
Hi, my problem is that I can't get getElementById to find the ID of any
controls on my page. To whit:
The following code-behind returns the error, "lblErrorText is
undefined.":
...
|
by: Nevyn Twyll |
last post by:
Is there any way I can use a code-behind event (like a btn_Click event)
to write some javascript into the Response?
I was thinking of using Response.Write() to write the following code into
the...
|
by: Asha |
last post by:
hello, from my main page, i have an iframe which calls another .aspx file;
and the other .aspx file will response.write values to it. but i keep getting
the below message. can someone pleasehelp me...
|
by: Charles A. Lackman |
last post by:
Hello,
I have an ASPX page that is storing data into a session Variable:
Session("Name") = "Chuck"
When the User clicks "Next" on the page, it naviages to "Details.aspx",
Details.aspx has two...
|
by: Filip De Backer |
last post by:
Hi everyone,
string script = "";
script += "<script language='javascript'>";
script += "window.open('showdoc.aspx');";
script += "</script>";
Response.Write(script);
After the execution of...
|
by: Tiago Vieira |
last post by:
Hi everybody,
I'm trying to insert a piece of javascript inside of a web service method
but It's not working. Have somebody already tryed to do it?
Folow a piece of my code below.
---------...
|
by: =?Utf-8?B?SmFzb24gSGFydHNvZQ==?= |
last post by:
I get the error:
Sys.WebForms.PageRequestManagerParserErrorException: The message received
from the server could not be parsed. Common causes for this error are when
the response is modified by...
|
by: satyabhaskar |
last post by:
hi all,
In my web page i have created radio buttons dynamically on to the page .....following is my code
string Course, Semester, Section;
int rowsCount;
string con =...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |