page layout changes after response.write

G

Guest

Hi everyone,

string script = "";
script += "<script language='javascript'>";
script += "window.open('showdoc.aspx');";
script += "</script>";
Response.Write(script);

After the execution of this code, the layout of my aspx page changes:
the font gets bigger, the datagrid (font, grid) gets bigger, ...

So is there another way to runs a javascript in code.

thanks,

Filip
 
E

eruth

Have you tried looking up Page.RegisterClientScriptBlock, or Page.
RegisterStartupScript to be used in the code behind?
 
G

Guest

The reason that the page changes visually is that the script you write
will end up before the doctype tag. That makes the browser ignore the
doctype, and the page is displayed in quirks mode.

Use Page.RegisterClientScriptBlock or Page.
RegisterStartupScript to add a script to the page as eruth suggested.
Then it will be placed in the code of the page and not before the code.
 
G

Guest

But I want to call the javascript in my C# code.
Not in my aspx page with a html button.

When I click on an asp button, I have some cod that updates teh database and
the opens a new window.
That's the problem, with the RegisterClientScriptBlock I can't call the
javascript function in C# (I think)
 
G

Guest

Of course you can't call a javascript function from C#. The server code
and the client code don't exist at the same time and don't exist on the
same place. But that is not a problem.

If you don't put the javascript commands in a javascript function, they
will be executed when the page loads. Just as they did when you wrote
them out with Response.Write.
 
Joined
Sep 20, 2007
Messages
1
Reaction score
0
Ok. So I know this is an old post, but it might help someone who comes looking for an answer.

My work-around was to
Response.Write([doctype.....])

before
Response.Write([javascript])

Not very eligant, but it does the job.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top