Solved

calling a javascript routine via .cs file

Posted on 2007-11-14
11
1,692 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 3

Expert Comment

by:basharat_rehman
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
I see, thank you for your time and efforts :-)
0
 
LVL 3

Expert Comment

by:basharat_rehman
Comment Utility
you re welcome
Basharat
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

763 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

9 Experts available now in Live!

Get 1:1 Help Now