C# ScriptManager.RegisterClientScript 在异步面板内 FormView 内的 UserControl 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/127283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ScriptManager.RegisterClientScript in a UserControl within a FormView inside an Async Panel
提问by Daniel
I'm having an annoying problem registering a javascript event from inside a user control within a formview in an Async panel. I go to my formview, and press a button to switch into insert mode. This doesn't do a full page postback. Within insert mode, my user control's page_load event should then register a javascript event using ScriptManager.RegisterStartupScript:
我在异步面板的表单视图中从用户控件内部注册 javascript 事件时遇到了一个烦人的问题。我转到我的表单视图,然后按一个按钮切换到插入模式。这不会进行整页回发。在插入模式下,我的用户控件的 page_load 事件应该使用 ScriptManager.RegisterStartupScript 注册一个 javascript 事件:
ScriptManager.RegisterStartupScript(base.Page, this.GetType(), ("dialogJavascript" + this.ID), "alert(\"Registered\");", true);
However when I look at my HTML source, the event isn't there. Hence the alert box is never shown. This is the setup of my actual aspx file:
但是,当我查看我的 HTML 源代码时,该事件并不存在。因此,永远不会显示警报框。这是我实际的 aspx 文件的设置:
<igmisc:WebAsyncRefreshPanel ID="WebAsyncRefreshPanel1" runat="server">
<asp:FormView ID="FormView1" runat="server" DataSourceID="odsCurrentIncident">
<EditItemTemplate>
<uc1:SearchSEDUsers ID="SearchSEDUsers1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
Hello
<asp:Button ID="Button1" runat="server" CommandName="Edit" Text="Button" />
</ItemTemplate>
</asp:FormView>
</igmisc:WebAsyncRefreshPanel>
Does anyone have any idea what I might be missing here?
有谁知道我在这里可能会遗漏什么?
回答by Dave Anderson
Have you tried using RegisterClientSideScript? You can always check the key for the script with IsClientSideScriptRegistered to ensure you don't register it multiple times.
您是否尝试过使用 RegisterClientSideScript?您始终可以使用 IsClientSideScriptRegistered 检查脚本的密钥,以确保您不会多次注册它。
I'm assuming the async panel is doing a partial page past back which doesn't trigger the mechansim to regenerate the startup scripts. Perhaps someone with a better understanding of the ASP.Net Page Life Cycle and the CLR can fill in those blanks.
我假设异步面板正在执行部分页面过去,这不会触发机制重新生成启动脚本。也许对 ASP.Net 页面生命周期和 CLR 有更好理解的人可以填补这些空白。
回答by Christian
Try this, i got the same issue
试试这个,我遇到了同样的问题
ScriptManager.RegisterClientScriptBlock(MyBase.Page, Me.[GetType](),
("dialogJavascript" + this.ID), "alert(\"Registered\");", True)
This worked for me!
这对我有用!
回答by Amrik
For me that works fine. resizeChartMid()
is a function name.
对我来说效果很好。 resizeChartMid()
是一个函数名。
ScriptManager.RegisterStartupScript(this, typeof(string), "getchart48", "resizeChartMid();", true);