Click to See Complete Forum and Search --> : Help me-Translate JavaScrip code to C# (or VB)


TrongTuan
July 6th, 2003, 10:11 PM
Hi all,

I have written code by JavaScrip to popup a window (popups/newInfor.htm ) when user enter to the my start page (index.html). It is as bellow:


<script language="javascript">
function OpenPage(){
window.open("Popup/newInfor.htm, "", "toolbar=No,location=No,directories=no,status=no,menubar=No,scrollbars=No,resizable=no,copyhistory=No,width=460,height=220,left=200, top=180")
}
</script>
</head>

<body topmargin="0" marginheight="0" leftmargin="0" marginwidth="0" bgcolor="#4D79B0" onload=OpenPage()>


Now I 'm starting with .NET. I want to translate these code to C# or VB.NET. I think that I have to write some thing in Page_Load event. But I do not know how to do it. Anyone can help me ?

Thank you

Neildw
July 7th, 2003, 02:20 AM
Hi.
As far as my knowledge is.
Is the (Window.Open). A client side request.
This means that you will still use Jscript / VBScript to do Client side Request..
So you do not have to re write this in ASP.Net
I’m Currently look at how to open windows from the server side…
Will get back to you as soon as I know..

Rohit Kukreti
July 9th, 2003, 10:32 AM
Hi TrongTuan,

I feel u don't need to convert the javascript code to C# or VB.NET.
U can call the script from srvr side. Use the code below



System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script language=javascript>") ;
sb.Append("alert('hello!!!');") ;
sb.Append("</script>");

if (!(IsStartupScriptRegistered("HighTher")))
RegisterStartupScript("HighTher", sb.ToString()) ;



In the code above 2nd line wud appear as sb.Append("") instead therez some code there. U won't c the code. Just click View and click source. There search for System.Text.StringBuilder sb . u'll have the whole code.
Replace the alert with ur javascript code. Place the code in ur Page_Load event of ur asp.net app. Above code is in C#.

Hope this helps

bye,
Rohit

coolbiz
July 9th, 2003, 12:01 PM
Well you cannot open a new window on the client from the server side. That would be a big security issue right?

You can, however, use the same script and append it from your ASP.NET page as illustrated by Rohit :)

-Cool Bizs