简体   繁体   English

将用户控件加载到RadToolTip中?

[英]Load user control into RadToolTip?

I'm trying to load a user control into a RadToolTip upon button click. 我试图在单击按钮时将用户控件加载到RadToolTip Once I click the button, I want to load the user control and then call the control's Initialize method, passing a collection of objects I have stored in the page viewstate. 单击按钮后,我想加载用户控件,然后调用控件的Initialize方法,并传递存储在页面viewstate中的对象的集合。

Here is the RadToolTip markup: 这是RadToolTip标记:

<telerik:RadToolTip runat="server" ID="_MyToolTip" HideEvent="ManualClose" 
    Position="Center" Width="500px" Height="400px" Animation="Fade"
    ShowEvent="OnClick" ShowDelay="0" RelativeTo="Element"
    TargetControlID="_MySelectButton" RenderInPageRoot="True" />

Here is the Click event handler for MyButton : 这是MyButtonClick事件处理程序:

protected void _MySelectButton_Click(object sender, EventArgs e)
{
    Control ctrl = Page.LoadControl(@"~/UserControls/MyUserControl.ascx");

    var muc = (ctrl as MyUserControlClass);

    muc.Initialize(_MyViewStateCollection); 
}

I want it so that when _MySelectButton_Click fires, it will create a new instance of MyUserControl , and then that event will propagate up into the RadToolTip so that the tooltip appears, and then the user control within the tooltip. 我希望这样做,以便在_MySelectButton_Click触发时,它将创建MyUserControl的新实例,然后该事件将传播到RadToolTip以便出现工具提示,然后出现在工具提示中的用户控件。 However, right now only the RadToolTip appears, with no user control within it. 但是,现在仅显示RadToolTip ,其中没有用户控件。

I found this post on Telerik's site which states: 我在Telerik的网站上发现了该帖子 ,其中指出:

Click events are not fired for a tooltipified element 没有为工具提示的元素触发点击事件

The RadToolTip registers event handlers for the client-side events and therefore they cancel the further click propagation so that the tooltip remains visible, as a postback would hide it. RadToolTip为客户端事件注册事件处理程序,因此它们取消了进一步的单击传播,以便工具提示保持可见,因为回发会将其隐藏。 This means that when the ShowEvent is set to OnClick elements such as Buttons, CheckBoxes, RadioButtons, LinkButtons may not fire their server events or even their client-side behavior may change (espeacially for the RadioButton and CheckBox - they will not change their states, as the click is cancelled). 这意味着当ShowEvent设置为按钮,复选框,单选按钮,链接按钮之类的OnClick元素时,它们可能不会触发其服务器事件,甚至客户端行为也可能发生变化 (尤其是对于单选按钮和CheckBox,它们不会更改其状态,因为点击被取消了)。 To avoid this set the ShowEvent to OnFocus or to OnMouseOver, for example. 为了避免这种情况,例如,将ShowEvent设置为OnFocus或OnMouseOver。 The same holds true for the RadToolTipManager as well. RadToolTipManager也是如此。

If the problem is that the button's Click is essentially incompatible given that the RadToolTip is preventing the click from propagating, how can I achieve the desired behavior? 如果问题是由于RadToolTip阻止了点击的传播,则该按钮的“ Click本质上是不兼容的,我该如何实现所需的行为? Bottom line, I want to be able to click a button, open a tooltip, then open my user control within that tooltip. 最重要的是,我希望能够单击一个按钮,打开一个工具提示,然后在该工具提示中打开我的用户控件。 Please help, thanks! 请帮忙,谢谢!

I found this post on Telerik's site where someone was having issues having two RadToolTipManager objects on the same page. 我在Telerik的网站上发现了此帖子 ,那里的某个人在同一页面上有两个RadToolTipManager对象时遇到了问题。

As I've been trying to add the RadToolTip to a page with an already existing RadToolTipManager , I decided to change my RadToolTip into an additional RadToolTipManager and explicitly specify the TargetControlID to reference _MySelectButton , and now the button click produces the tooltip along with the expected user control elements. 当我试图将RadToolTip添加到具有现有RadToolTipManager的页面时,我决定将RadToolTip更改为其他RadToolTipManager并明确指定TargetControlID以引用_MySelectButton ,现在单击按钮会产生工具提示以及预期的提示用户控制元素。

<telerik:RadToolTipManager runat="server" ID="_MyToolTipManager"
    OffsetY="-1" OffsetX="250" HideEvent="ManualClose" Width="500" Height="400"
    RelativeTo="Element" RenderInPageRoot="True"
    OnAjaxUpdate="MySelectButtonToolTipManagerAjaxUpdate"
    ShowEvent="OnClick" Animation="Slide">

    <TargetControls>
        <telerik:ToolTipTargetControl TargetControlID="_MySelectButton" />
    </TargetControls>

</telerik:RadToolTipManager>

Here is the associated handler for the RadToolTipManager 's OnAjaxUpdate event: 这是RadToolTipManagerOnAjaxUpdate事件的关联处理程序:

protected void MySelectButtonToolTipManagerAjaxUpdate(
    object sender, ToolTipUpdateEventArgs e)
{
    Control ctrl = Page.LoadControl(@"~/UserControls/MyUserControl.ascx");
    ctrl.ID = "MyUserControl";
    e.UpdatePanel.ContentTemplateContainer.Controls.Add(ctrl);           
    var li = (ctrl as MyUserControlClass);

    li.Initialize(MyViewStateCollection);
}

Problem solved! 问题解决了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM