从后面的C#code调用JS功能 [英] Call JS function from code behind C#
本文介绍了从后面的C#code调用JS功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个功能叫做onRowClick和RowClick工作正常。我想将它移动到一个按钮,后面调用从code的作用。出于某种原因,无法触发功能..任何人都知道为什么,我该如何解决这一问题?
aspx.cs
如果(e.CommandName ==Addvoucher)
{ GridDataItem项目=(GridDataItem)e.Item; 变种的id = item.GetDataKeyValue(的RowID); ClientScript.RegisterStartupScript(Page.GetType(),的myKey,RowClick(+ ID +);,真); }
ASPX
<脚本>
VAR popUpObj;
功能RowClick(发件人,EventArgs){
VAR filterId = eventArgs.getDataKeyValue('ROWID');
popUpObj = window.open(voucher.aspx?参数=+ filterId +
ModalPopUp
工具栏=没有,+
滚动条=没有,+
位置=没有,+
状态栏=没有,+
菜单栏=没有,+
调整大小= 0,+
宽度= 530,+
高度= 500,+
左= 450,+
顶= 130
);
popUpObj.focus();
LoadModalDiv();
}
功能LoadModalDiv()
{
变种bcgDiv =的document.getElementById(divBackground);
bcgDiv.style.display =块;
} 功能HideModalDiv(){
变种bcgDiv =的document.getElementById(divBackground);
bcgDiv.style.display =无;
} < / SCRIPT>
在页面voucher.aspx
<脚本类型=文/ JavaScript的> 功能的OnClose(){ 如果(window.opener = NULL&放大器;!&安培;!window.opener.closed){
window.opener.location.reload(); //刷新父时,弹出近
// window.opener.HideModalDiv();
} //如果(window.closed ==真)window.open(〜/ routedoc.aspx);
}
window.onunload =的OnClose; < / SCRIPT>
解决方案
更改您的js函数像这样
函数RowClick(filterId){popUpObj = window.open(voucher.aspx?参数=+ filterId +
ModalPopUp
工具栏=没有,+
滚动条=没有,+
位置=没有,+
状态栏=没有,+
菜单栏=没有,+
调整大小= 0,+
宽度= 530,+
高度= 500,+
左= 450,+
顶= 130
);
popUpObj.focus();
LoadModalDiv();
}
有没有必要这个系列现在 VAR filterId = eventArgs.getDataKeyValue('的RowID')的;
现在你可以直接使用参数 filterId
在js函数。
I have a function onRowClick called RowClick and is working fine. I am trying to move it to a button and call the function from the code behind. For some reason is not triggering the function.. Anyone knows why and how I can fix this?
aspx.cs
if (e.CommandName == "Addvoucher")
{
GridDataItem item = (GridDataItem)e.Item;
var id = item.GetDataKeyValue("RowID");
ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "RowClick("+id+");", true);
}
aspx
<script>
var popUpObj;
function RowClick(sender, eventArgs) {
var filterId = eventArgs.getDataKeyValue('RowID');
popUpObj = window.open("voucher.aspx?param=" + filterId + "",
"ModalPopUp",
"toolbar=no," +
"scrollbars=no," +
"location=no," +
"statusbar=no," +
"menubar=no," +
"resizable=0," +
"width=530," +
"height=500," +
"left = 450," +
"top=130"
);
popUpObj.focus();
LoadModalDiv();
}
function LoadModalDiv()
{
var bcgDiv = document.getElementById("divBackground");
bcgDiv.style.display="block";
}
function HideModalDiv() {
var bcgDiv = document.getElementById("divBackground");
bcgDiv.style.display = "none";
}
</script>
IN page voucher.aspx
<script type = "text/javascript">
function OnClose() {
if (window.opener != null && !window.opener.closed) {
window.opener.location.reload(); //refreshing parent when popup close
// window.opener.HideModalDiv();
}
//if (window.closed==true) window.open("~/routedoc.aspx");
}
window.onunload = OnClose;
</script>
解决方案
Change your js function like this
function RowClick(filterId) {
popUpObj = window.open("voucher.aspx?param=" + filterId + "",
"ModalPopUp",
"toolbar=no," +
"scrollbars=no," +
"location=no," +
"statusbar=no," +
"menubar=no," +
"resizable=0," +
"width=530," +
"height=500," +
"left = 450," +
"top=130"
);
popUpObj.focus();
LoadModalDiv();
}
There is no need of this line now var filterId = eventArgs.getDataKeyValue('RowID');
Now you can directly use the parameter filterId
in your js function.
这篇关于从后面的C#code调用JS功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文