execute JavaScript using C#

M

marianowic

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
 
G

Guest

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
 
M

marianowic

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top