javascript函数是没有得到从code呼叫时,它被放在主页上落后 [英] Javascript function is not getting call from code behind when it is put on master page
问题描述
我有2页命名为: Abc.aspx和popupAbc.aspx
现在在 Abc.aspx 我有以下按钮,点击其中我打开 popupAbc.aspx 作为弹出:
< ASP:按钮的ID =btnOpenChildAbcPopup=服务器文本=打开UseSubmitBehavior =假的CausesValidation =FALSE的OnClick =btnOpenChildAbcPopup_Click/>
code背后:
保护无效btnOpenChildAbcPopup_Click(对象发件人,EventArgs的发送)
{
字符串的URL =../ popupAbc.aspx
ScriptManager.RegisterStartupScript(页,的GetType(),警告,OpenChildAbcPopup('+网址+');,
真正);
}功能OpenChildAbcPopup(URL){
$ .fancybox({
在onStart':函数(){$ .fancybox.hideActivit()},
的onComplete':函数(){$ .fancybox.hideActivity()},
titleShow':'真',
titlePosition':'过',
titleFormat':'formatTitle',
HREF:URL,// popupAbc.aspx
类型:IFRAME,
'宽度':'1000',
高度:'500',
fitToView:假的,
autoSize的:假的,
hideOnOverlayClick:假的,
hideOnContentClick:假的,
overlayOpacity':0.7,
enableEscapeButton:假的,
closeEffect':'无'
});
$ .fancybox.hideLoading();
返回false;
}
下面到目前为止万物完美的作品和按钮的点击我的 popupAbc.aspx
在弹出框,但问题完全打开,这与本 popupAbc.aspx
。
我在 popupAbc.aspx
一个按钮中,我会保存一些数据和保存数据后,我想再次调用
javascript函数是母版页上但javascript函数并没有叫。
这是我的网页: popupAbc.aspx
<%@页面语言=C#AutoEventWireup =真的MasterPageFile =〜/ MyMaster.MastercodeBehind =popupAbc.aspx.cs继承= popupAbc.aspx%GT;< ASP:按钮的ID =btnSubmit按钮=服务器文本=保存的OnClick =btnSubmit_ClickUseSubmitBehavior =真的ValidationGroup =P1/> 保护无效btnSubmit_Click(对象发件人,EventArgs的发送)
{
// code在数据库中保存表单数据,之后调用JavaScript函数
//是MyMaster页
ScriptManager.RegisterStartupScript(页,的GetType(),的js,ExitMyCurrentFancyBox();,真);
}
但在Firebug的控制台被扔的错误的没有定义ExitMyCurrentFancyBox
当我把这个 ExitMyCurrentFancyBox 在功能上我的 popupAbc.aspx
则成功调用,但是当我把这个我的母版页上,然后它不来电。
函数ExitMyCurrentFancyBox(){
警报()
}
注意:我Abc.aspx 使用更新面板
和 popupAbc.aspx 犯规用途更新面板
。
谁能告诉我,为什么当我把它的主网页和JavaScript函数调用不如何调用它时,它是母版页??
在我已经尝试了所有这一切,但仍以下任何不工作:
// ScriptManager.RegisterStartupScript(页,的GetType(),警告,ExitMyCurrentFancyBox();,真正的);
// ScriptManager.RegisterStartupScript(页,的GetType(),警告,ExitMyCurrentFancyBox();,真正的);
//ClientScript.RegisterClientScriptBlock(的GetType(),SAS,CloseFancyboxtl();,真);
// ScriptManager.RegisterStartupScript(此,this.GetType(),ntmtch,ExitMyCurrentFancyBox();,真);
// ScriptManager.RegisterStartupScript(页,Page.GetType(),msg中,ExitMyCurrentFancyBox();,真);
//ScriptManager.RegisterStartupScript(this,this.GetType(),msg中,ExitMyCurrentFancyBox;,真);
ScriptManager.RegisterClientScriptBlock(this.Page,的GetType(),Guid.NewGuid()的ToString(),ExitMyCurrentFancyBox();,真);
发布可能的解决方案,由于您的要求。
下一个方法添加到您的母版:
公共无效ShowMyJavascript(){
的Response.Write(< SCRIPT LANGUAGE =JavaScript的'>警报('这是我的显示为一条警告消息');< / SCRIPT>中);
}
而在你的页面内容:
this.Master.ShowMyJavascript();
I have 2 pages named as :Abc.aspx and popupAbc.aspx
Now on Abc.aspx i have below button on click of which i am opening popupAbc.aspx as pop up:
<asp:Button ID="btnOpenChildAbcPopup" runat="server" Text="Open" UseSubmitBehavior="false" CausesValidation="False" OnClick="btnOpenChildAbcPopup_Click" />
Code Behind:
protected void btnOpenChildAbcPopup_Click(object sender, EventArgs e)
{
string url="../popupAbc.aspx";
ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "OpenChildAbcPopup('" + url + "');",
true);
}
function OpenChildAbcPopup(url) {
$.fancybox({
'onStart ': function () { $.fancybox.hideActivit() },
'onComplete': function () { $.fancybox.hideActivity() },
'titleShow': 'true',
'titlePosition': 'over',
'titleFormat': 'formatTitle',
'href': url,//popupAbc.aspx
'type': 'iframe',
'width': '1000',
'height': '500',
'fitToView': false,
'autoSize': false,
'hideOnOverlayClick': false,
'hideOnContentClick': false,
'overlayOpacity': 0.7,
'enableEscapeButton': false,
'closeEffect': 'none'
});
$.fancybox.hideLoading();
return false;
}
Here up till now everythings works perfectly and on click of button my popupAbc.aspx
opens perfectly in pop up box but problem is with in this popupAbc.aspx
.
i have one button in popupAbc.aspx
in which i will save some data and after saving data i would like to again call the
javascript function which is on master page but that javascript function is not calling.
This is my page:popupAbc.aspx
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MyMaster.Master" CodeBehind="popupAbc.aspx.cs" Inherits="popupAbc.aspx" %>
<asp:Button ID="btnSubmit" runat="server" Text="Save" OnClick="btnSubmit_Click" UseSubmitBehavior="true" ValidationGroup="p1" />
protected void btnSubmit_Click(object sender, EventArgs e)
{
//code for saving form data in database and after that call javascript function which
//is on MyMaster page
ScriptManager.RegisterStartupScript(Page, GetType(), "Js", "ExitMyCurrentFancyBox();", true);
}
But in firebug console it is throwing error that ExitMyCurrentFancyBox is not defined.
When i put this ExitMyCurrentFancyBox function in my popupAbc.aspx
then it is calling successfully but when i put this on my master page then it is not calling.
function ExitMyCurrentFancyBox() {
alert()
}
Note:My Abc.aspx uses update panel
and popupAbc.aspx doesnt uses update panel
.
Can anybody tell me why that Javascript function is not calling when i put it on master page and how to call it when it is on master page??
I have tried all this but still any of below is not working:
// ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "ExitMyCurrentFancyBox();", true);
// ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "ExitMyCurrentFancyBox();", true);
//ClientScript.RegisterClientScriptBlock(GetType(), "sas", "CloseFancyboxtl();", true);
// ScriptManager.RegisterStartupScript(this, this.GetType(), "ntmtch", "ExitMyCurrentFancyBox();", true);
// ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", "ExitMyCurrentFancyBox();", true);
//ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "ExitMyCurrentFancyBox;", true);
ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), Guid.NewGuid().ToString(), "ExitMyCurrentFancyBox();", true);
Posting possible solution due to your request.
Add next method to your MasterPage:
public void ShowMyJavascript(){
Response.Write("<script language='javascript'>alert('Here is my message to be displayed as an alert');</script>");
}
And in your content page:
this.Master.ShowMyJavascript();
这篇关于javascript函数是没有得到从code呼叫时,它被放在主页上落后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!