1

initially a table is invisible in the ASP.NET page. on button click event, it should go to the code behind and from there i need to call a function in javascript. In that javascript function i should make the table to be visible. Is this possible?? Somebody please help me out

2

7 Answers 7

2

Try this:

Page.ClientScript.RegisterStartupScript(GetType(), "MyKey", "Myfunction();", true);
Sign up to request clarification or add additional context in comments.

Comments

1

try the following code

ScriptManager.RegisterStartupScript(this, this.GetType(), "isActive", "alert('hello');", true);

Here "this" is used for control by which you want to fire this. this.Gettype() is used get type of Client Script "isActive" it is the unique key. After all these the javascript code. it could be function whatever you want to do. and lastly there is true that ask you either you want to script tag for the javascript code you are writing here or not.

Comments

1
     ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "HelloWorld", "HelloWorld();", true);

Comments

0

From code behind you can invoke javascript something like this

ScriptManager.RegisterStartupScript(Page, GetType(Page), "ScriptName", 'document.getelementById("tableId").display = inline;' , True)

But i would recommend to do it on client side without posting a page. Post the page only if you need to access server resources.

1 Comment

It wouldn't be alert("Hello"), instead you'd write the script to make your table visible. Just to point things clear.
0

You can call javascript function using code behind as:

 ScriptManager.RegisterStartupScript(page, typeof(Page), Guid.NewGuid().ToString(), "callJavaScriptFunction();", true);

Comments

0

calling javascript functions from code behind is not possible(if we leave apart the newer sockets).
after the page has loaded once fro the web server then there is no way for the server to know what data to send to which user..
you should probably try out sending an ajax request and execute some code depending upon the response got from the server.

Comments

0

Try This

string str="<script>alert(\"ok\");</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", str, false);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.