calling a javascript routine via .cs file

How would you call this javascript routine via the .cs file ?  (c#, asp.net 2.x)

<a href="javascript: openwindow()">Hello World</a>

Thank you in advanced for your time and efforts with this enquiry.
amillyardAsked:
Who is Participating?
 
basharat_rehmanConnect With a Mentor Commented:
in aspx file:
------------
 <asp:Button ID="Button1" runat="server" Text="Button" />

in .cs file
-----------
protected void Page_Load(object sender, EventArgs e)
        {
                  this.Button1.Attributes.Add("onclick", "javascript:window.open('','','');");
        }


basharat
0
 
basharat_rehmanCommented:
Your question is vague
Do you want to call in c# file like this?
 Response.Write("<a href=\"javascript:window.open('','','');\">Hello World</a>");
this will put this link on top of your webpage

well you can also put a hyperlink in aspx file
             <a id ="Link1" href="#" runat="server" >Hello world</a>
and in onload of page in .cs file put
             this.Link1.Attributes["href"] = "javascript:window.open('','','');";


clear your question if this not the answer
basharat
0
 
amillyardAuthor Commented:
basharat_rehman:

apologies for not explaining clearer.

needed to know how to call the javascript routine from the .cs side of things -- i.e. the equivant to calling via the hyperlink script.

i.e. page loading, or via a button press ... the .cs process the javascript calling routine.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
amillyardAuthor Commented:
ok -- looking at your scripting further -- it appears that you are not needing to call a seperate javascript file, as able to process javascript withing the .cs file at the same time.  on the aspx version, I had a seperate javascript file contained.
0
 
amillyardAuthor Commented:
to open a window (i.e. once clicking on a button) - what do I need to add to the javascript line to make that happen please?

        protected void Button_OpenWindow_Click(object sender, EventArgs e)
        {
               javascript:window.open('','','');
        }
0
 
basharat_rehmanCommented:

just link up your javascript file in your aspx file and call the required function just as i did in example
example of linking .js file
<script language="javascript" type="text/javascript" src="sample.js"></script>

basharat
0
 
basharat_rehmanCommented:
window.open ("www.experts-exchange.com","mywindow","menubar=1,resizable=1,width=350,height=250");
for details see
http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
basharat
0
 
amillyardAuthor Commented:
I am getting a complile on window:

The name 'window' does not exist in the current context
______________________________________________________________

protected void Button_OpenWindow_Click(object sender, EventArgs e)
        {
               javascript:window.open('','','');
        }
0
 
basharat_rehmanCommented:

you cannot call this at server side like this.
You have to register the function on onclick event of button in page load first.
then when the html of the page is rendered it will be added to the button's attributes
the at client side when you click on the button it will open a window with out post back to server.
do this as: wait my next message.........................
0
 
amillyardAuthor Commented:
I see, thank you for your time and efforts :-)
0
 
basharat_rehmanCommented:
you re welcome
Basharat
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.