473,434 Members | 1,404 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,434 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 21226
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.