Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a function in Javascript which makes a label invisible. I want to call this function from the code behind. I am not able to make it invisible. Here are both the lines of code.

Code behind:

C#
ClientScript.RegisterStartupScript(GetType(), DateTime.Now.ToString(), "MyFunction();", true);


Javascript:

JavaScript
function MyFunction()
       {
           document.getElementById("<%= Label8.ClientID %>").style.display = 'none'; 
       }


Pls let me know if there is any mistake. Looks like control is not going to method definition only.

Thank you
Posted

Hi,

try the following code. May be it help you.

C#
ScriptManager.RegisterStartupScript(this.Page, this.GetType(),"Myfun", "MyFunction();", false);


C#
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "MyFunction();", true);
 
Share this answer
 
check if there are multiple RegisterStartupScript blocks on your page.
If yes then you will have to name each script block differently



check clientscriptmanager.IsStartupScriptRegistered for that and in that case you can overload RegisterStartupScript
 
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