Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a div in asp page.I want to visible the div when I click on a button and then the button do something,at last after the button work finish the div will be invisible.For visible and invisible I have a javascript function.Now How to call javascript in code behind.

functions are(in .js file):

JavaScript
function invisiblediv(element)
{
    document.getElementById(element).style.display='none';
}
function visiblediv(element)
{
    document.getElementById(element).style.display='visible';
}


I have tried registerclient script method but that is not working.
Don't tell to use response.write() to call javascript.This is not helpful for all purpose.
Posted
Updated 9-May-12 18:36pm
v2

try this
//refere .js file in .aspx page
 <script src="JScript.js" type="text/javascript"></script>

//calling javascript function in .cs file
ScriptManager.RegisterStartupScript(Page, this.GetType(), "script", "invisiblediv('" + elementid + "');", true);
 
Share this answer
 
v3
In the button click call the javascript to display the div as:
C#
 string script = "<script language='javascript'>visiblediv()</script>";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), script, false);



and for closing call the closing function somewhere at the appropriate palce, for this i will suggest to place a closing link in the div only such as :
HTML
<a href="#"><img src="../images/close_icon.gif" alt="Close" width="14" height="14" border="0"
  önclick="invisiblediv()" style="cursor: pointer;" /></a>
 
Share this answer
 
v3
Comments
Member 10286017 3-Oct-13 3:08am    
i have a normal c# code page where i need to call a .asp file which contains javascript code
could u please help me how to do so??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900