Solved

calling a javascript routine via .cs file

Posted on 2007-11-14
11
1,697 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:amillyard
  • 6
  • 5
11 Comments
 
LVL 3

Expert Comment

by:basharat_rehman
ID: 20280248
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
 

Author Comment

by:amillyard
ID: 20280365
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
 

Author Comment

by:amillyard
ID: 20280391
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
 

Author Comment

by:amillyard
ID: 20280444
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
 
LVL 3

Expert Comment

by:basharat_rehman
ID: 20280446

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Expert Comment

by:basharat_rehman
ID: 20280477
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
 

Author Comment

by:amillyard
ID: 20280504
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
 
LVL 3

Expert Comment

by:basharat_rehman
ID: 20280531

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
 
LVL 3

Accepted Solution

by:
basharat_rehman earned 500 total points
ID: 20280559
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
 

Author Comment

by:amillyard
ID: 20280603
I see, thank you for your time and efforts :-)
0
 
LVL 3

Expert Comment

by:basharat_rehman
ID: 20280640
you re welcome
Basharat
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now