ASP.NET WebControl only allow one instance of control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ShadowLocke
    New Member
    • Jan 2008
    • 116

    ASP.NET WebControl only allow one instance of control

    I created a custom webcontrol that could be used inside of other controls. It only needs to be rendered once on any page that uses it no matter how many other controls call for it.

    How can I prevent the web control from rendering if another is already on the page?

    I tried
    Code:
    Page.FindControl("controls_static_id") == null
    inside of the Render method but that didnt work.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Could you please clarify the context in which you are using the WebUser?
    Your approach is not going to be easy to implement. If you provide more information on what the web user control does and how it should be used we may be able to suggest a different approach to your problem.

    -Frinny

    Comment

    • ShadowLocke
      New Member
      • Jan 2008
      • 116

      #3
      Sorry, I forgot about this post. The control is a custom tooltip control. What I ended up doing was taking a look at how the Ajax.Net ScriptManager control did it. soo..

      Code:
              private Boolean ToolTipExists()
              {
                  return (Page.Items[typeof(u_tooltip)] != null);
              }
      
              protected override void OnInit(EventArgs e)
              {
                  RenderMe = !ToolTipExists();
                  Page.Items[typeof(u_tooltip)] = this;
                  ...
      worked for me
      Originally posted by Frinavale
      Could you please clarify the context in which you are using the WebUser?
      Your approach is not going to be easy to implement. If you provide more information on what the web user control does and how it should be used we may be able to suggest a different approach to your problem.

      -Frinny

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Thanks for taking the time to post your solution!

        :)

        Comment

        Working...