Write javascript 'into' a c# .NET webapplikation

N

Nat

Help, I have following code:

-----------------------------------------------------

protected override void Render(HtmlTextWriter w)
{
if (helpString!=null)
{
w.write("<span class='tooltipiconouter'><img title =
'"+this.helpString+"' class='tooltipIconInner' align='center' src =
'../Lib/images/questionmark.gif' a href='#' onclick = 'myWin =
window.open(); myWin.document.write(\"" +helpString+
"\")'></a></span>");
}

-----------------------------------------------------

I want to add some parameters in to the window.open() or in the
document.write(), så I can control the window size, bg. color and name
-
how do I write that into the code above??

(If I fx. write: window.open('','Something','width=200 height'),
depending on where I put it in, it either doesn't open a new window,
or it reseizes the image).

Thanks
 
A

Antenna

I suggest you rewrite it a bit, like so:

protected override void Render(HtmlTextWriter w)
{
if (helpString!=null)
{
w.write(
"<span class='tooltipiconouter'>" +
"<img title=\"" + this.helpString +
"\" class=\"tooltipIconInner\" align=\"center\" " +
"src=\"../Lib/images/questionmark.gif\">" +
"<a href=\"#\" onclick=\"myWin=window.open('','Something','width=200');
myWin.document.write('" + helpString +
"')\"></a></span>"
);
}

<!untested!>
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You have to escape the " of the parameters of window.open:

w.Write("..... " + " onClick='
win=window.Open(\"theurl\",\"thename\",\"width=200,height=200\");return
false;' ");

Hope this help,
 
N

Nat

I made some few ajustments to the code Antenna gave me, so it could
build, and it seems to work, but it doesn't open any window..why??

The code looks like this now:

--------------------------------------

protected override void Render(HtmlTextWriter w)
{
if (helpString!=null)
{
w.Write("<span class='tooltipiconouter'>" + "<img title=\"" +
this.helpString + "\" class=\"tooltipIconInner\" align=\"center\" " +
"src=\"../lib/images/questionmark.gif\">" + "<a href=\"#\"
onclick=\"myWin=window.open('','Something','width=200');
myWin.document.write('" + helpString + "')\"></a></span>");
}
}

-----------------------------

If I view the html code that is generated, it looks like this:

<td><span id="_ctl0_EditOrganization1_EXTLABEL1"
class="brod">Kundenummer</span><span class='tooltipiconouter'><img
title="bla bla bla bla" class="tooltipIconInner" align="center"
src="../lib/images/questionmark.gif"><a href=#
onclick="myWin=window.open('','Something','width=200');
myWin.document.write('bla bla bla bla')"></a></span></td>
 
N

Nat

I've solved the problem. Thanks for all your help.

The code (in onclick) have to look like this:

......
onclick = 'myWin = window.open(\"\", \"Tip\", \"width=200 height=300\")
......

Nat
 

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

Top