Solved

calling a javascript routine via .cs file

Posted on 2007-11-14
11
1,713 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

749 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