admin管理员组文章数量:1301552
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
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
Share asked Aug 6, 2012 at 6:23 user1575995user1575995 411 gold badge1 silver badge3 bronze badges 2-
Is that table a HTML table (
<table>
) or a ASP.NET Control? – Andre Calil Commented Aug 6, 2012 at 6:24 - 1 possible duplicate of How to call javascript function from code behind? – Artem Koshelev Commented Aug 6, 2012 at 6:25
7 Answers
Reset to default 2Try this:
Page.ClientScript.RegisterStartupScript(GetType(), "MyKey", "Myfunction();", true);
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.
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "HelloWorld", "HelloWorld();", true);
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 remend to do it on client side without posting a page. Post the page only if you need to access server resources.
You can call javascript function using code behind as:
ScriptManager.RegisterStartupScript(page, typeof(Page), Guid.NewGuid().ToString(), "callJavaScriptFunction();", true);
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.
Try This
string str="<script>alert(\"ok\");</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", str, false);
本文标签: how to call a javascript function from c code behindStack Overflow
版权声明:本文标题:how to call a javascript function from c# code behind - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741678757a2392040.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论