TelerikMVC控件,OnDocumentReady发射两次-TelerikMVCcontrols,OnDocumentReadyisfiringtwice
作者:黄小翻_618 | 来源:互联网 | 2023-05-17 15:41
ImnewtoTelerikMVCcontrols,sothismaybesomethingsimple.我是TelerikMVC控件的新手,所以这可能很简单。Ist
I'm new to Telerik MVC controls, so this may be something simple.
我是Telerik MVC控件的新手,所以这可能很简单。
I started out with making a new TelerikMvcApplication solution.
我开始制作新的TelerikMvcApplication解决方案。
Site.Master:
<%: Html.Telerik().ScriptRegistrar().DefaultGroup(group =>
group.Combined(true).Compress(true).Add("Index.js")) %>
Index.aspx:
<%: Html.Telerik().ScriptRegistrar().OnDocumentReady("Index.Init()") %>
Index.js:
var Index = function () {
return {
Init: function () {
alert('1');
}
};
} ();
When I load Index.aspx, the Init() function in Index.js is fired twice, so I see 2 alerts one after another. If I assign a click handler to a button inside the Init() function and hit the button with FireBug, it is actually showing 2 events being assigned to the button. Why is this happening?
当我加载Index.aspx时,Index.js中的Init()函数被触发两次,所以我看到一个接一个的2个警报。如果我将一个单击处理程序分配给Init()函数内的按钮并使用FireBug点击该按钮,它实际上显示为该按钮分配了2个事件。为什么会这样?
Edit
After some more firebugging, I figured out that both calls to ScriptRegistrar are being rendered. How do I make only master one to render?
经过一番讽刺之后,我发现两个对ScriptRegistrar的调用都被渲染了。如何只制作一个渲染的主人?
2 个解决方案