如何在后面的代码中调用javascript [英] how to call javascript in code behind

查看:84
本文介绍了如何在后面的代码中调用javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP页面中有一个div.我想在单击按钮时看到div,然后该按钮执行某些操作,最后在按钮工作完成后,div将不可见.对于可见和不可见,我有一个javascript函数.现在如何在后面的代码中调用javascript.

函数是(在.js文件中):

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):

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



我已经尝试过registerclient脚本方法,但是不起作用.
不要告诉使用response.write()来调用javascript.这并不是万能的.



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.

推荐答案

尝试一下
//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);


在该按钮中,单击调用javascript以将div显示为:
In the button click call the javascript to display the div as:
 string script = "<script language='javascript'>visiblediv()</script>";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), script, false);




对于关闭,请在适当位置的某个地方调用关闭函数,为此,我建议仅在div中放置一个关闭链接,例如:




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 :

<a href="#"><img src="../images/close_icon.gif" alt="Close" width="14" height="14" border="0"

  önclick="invisiblediv()" style="cursor: pointer;" /></a>


您可以尝试这个..会帮助您


http://www.aspdotnet-suresh.com/2012/04/aspnet-show-alert-message-from-code.html [
You can try this.. will help you


http://www.aspdotnet-suresh.com/2012/04/aspnet-show-alert-message-from-code.html[^]


这篇关于如何在后面的代码中调用javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆