Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

calling a javascript routine via .cs file

Posted on 2007-11-14
11
Medium Priority
?
1,733 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Suggested Courses

610 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