473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

execute JavaScript using C#

Hello.
I'm struggeling with one think.
I have got already registered JavaScript in my web application
(RegisterClientScriptBlock) and, ofcourse, I can invoke it with
methods like onClick(), onMouseOver(), etc. But I need to invoke it
from my C# code behind file. Te example is shown below?? Is it
possible?? Thanks for help

--------------------------- C# code -------------------------------

string showHideSearch;

showHideSearch = "<script type=\"text/javascript\"function
showOrHide(what) { if (document.getElementById) " +
" { var style2 =
document.getElementById(whichLayer).style; style2.display =
style2.display? \"\":\"block\";" +
" } else if (document.all) { var style2 =
document.all[whichLayer].style; style2.display = style2.display? \"\":
\"block\"; " +
" } else if (document.layers) { var style2 =
document.layers[whichLayer].style; style2.display = style2.display?
\"\":\"block\";" +
" } } </script";

RegisterClientScriptBlock("show_and_hide", showHideSearch);

-- And here I would like to invoke the JavaScript
-- like for ex: Page.Invoke("showOrHide"); --this is ofcourse wrong

Mar 5 '07 #1
3 21225
Hi,

ma********@gmail.com wrote:
Hello.
I'm struggeling with one think.
I have got already registered JavaScript in my web application
(RegisterClientScriptBlock) and, ofcourse, I can invoke it with
methods like onClick(), onMouseOver(), etc. But I need to invoke it
from my C# code behind file. Te example is shown below?? Is it
possible?? Thanks for help
JavaScript runs on the client, and C# runs on the server (well, in
ASP.NET at least). So how exactly do you want to invoke one using the other?

The best you can do is add a call to the method "showOrHide" at the end
of your script block. But still, it's not a direct invocation.

Greetings,
Laurent
>
--------------------------- C# code -------------------------------

string showHideSearch;

showHideSearch = "<script type=\"text/javascript\"function
showOrHide(what) { if (document.getElementById) " +
" { var style2 =
document.getElementById(whichLayer).style; style2.display =
style2.display? \"\":\"block\";" +
" } else if (document.all) { var style2 =
document.all[whichLayer].style; style2.display = style2.display? \"\":
\"block\"; " +
" } else if (document.layers) { var style2 =
document.layers[whichLayer].style; style2.display = style2.display?
\"\":\"block\";" +
" } } </script";

RegisterClientScriptBlock("show_and_hide", showHideSearch);

-- And here I would like to invoke the JavaScript
-- like for ex: Page.Invoke("showOrHide"); --this is ofcourse wrong

--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Mar 5 '07 #2
In order to get client-side script functions to run, your page would need to
emit legal Javascript method calls into your page, e.g.

Response.Write("<script>myFunction();</script>");

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ma********@gmail.com" wrote:
Hello.
I'm struggeling with one think.
I have got already registered JavaScript in my web application
(RegisterClientScriptBlock) and, ofcourse, I can invoke it with
methods like onClick(), onMouseOver(), etc. But I need to invoke it
from my C# code behind file. Te example is shown below?? Is it
possible?? Thanks for help

--------------------------- C# code -------------------------------

string showHideSearch;

showHideSearch = "<script type=\"text/javascript\"function
showOrHide(what) { if (document.getElementById) " +
" { var style2 =
document.getElementById(whichLayer).style; style2.display =
style2.display? \"\":\"block\";" +
" } else if (document.all) { var style2 =
document.all[whichLayer].style; style2.display = style2.display? \"\":
\"block\"; " +
" } else if (document.layers) { var style2 =
document.layers[whichLayer].style; style2.display = style2.display?
\"\":\"block\";" +
" } } </script";

RegisterClientScriptBlock("show_and_hide", showHideSearch);

-- And here I would like to invoke the JavaScript
-- like for ex: Page.Invoke("showOrHide"); --this is ofcourse wrong

Mar 5 '07 #3
Thanks a lot guys.
I ommit this problem by writing a simillar code in C# (server side) to
this in JavaScript.
I know that this is not so good solution (more code, less effective),
but I couldn't find better option.
Once more thanks for help.

Pozdro 600... marianowic

Mar 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jm | last post by:
I have a parent window: <script language="javascript"> function doSearch() { result=showModalDialog("searchmni.aspx?lastname=smith"); alert(result); } </script>
2
by: Dave | last post by:
Hi, I have a datagrid with a Templated column below. I want to execute some javascript before the postback to show a hidden "div" tag with static message of "Please Wait..." since the query takes...
0
by: Dexter | last post by:
Hello all, I have the following problem. I need to execute a javascript function of inside of a asp.net page. .... Private Sub execute_test() '... here a asp.net code '... here a asp.net code...
5
by: Scott Natwick | last post by:
Is there a way to execute a JavaScript from the Page_Load event? Or alternatively, is there a way to have it execute when the page is loaded? I am defining the script in the Page_Load event and...
1
by: Peter Dickson | last post by:
I am trying to pull data from a website into a database. Part of the website I am getting the data uses javascript to display the data. The only variable being passed to the javascript when it...
4
by: Ian Kelly | last post by:
Hi All, I have an .net form that is split into two frames. The left frame has a tree that displays a list of all the customers. The right frame displays the appropriate clients information. ...
4
by: Mark Miller | last post by:
I've been trying to execute a javascript function just before submit on a form that contains an <input type="file"> input field and it isn't working. The reason I want to do this is the end users...
4
by: j1dopeman | last post by:
Hi, I'd like to use a button to save and then submit a form. I can set the onlick of the button to mahButton_click or submit, but I can't figure out how to do both. It looks like c# can't...
1
by: mikegolden | last post by:
An application I'm working on makes extensive use of output parameters and return values, thus forcing me to use the ADODB Command object to execute the stored procs. For recordset returning stored...
6
by: moongeegee | last post by:
I have compile my java program as myjava.class. And I can run as "java myjava" without any program. As now, I need to execute myjava.class in javascript. Please shed a light how to execut "java...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.