WebParts - Usercontrol - Title

Last post 07-06-2005 9:17 PM by stucker79. 6 replies.

Sort Posts:

  • WebParts - Usercontrol - Title

    02-08-2005, 3:26 AM
    • Participant
      805 point Participant
    • richy_roo
    • Member since 12-18-2004, 1:24 PM
    • Posts 161
    If a webpart is a usercontrol, is there a way in code to programatically set the Title bar description (currently untitled[1]) in the ascx file?

    thanks
  • Re: WebParts - Usercontrol - Title

    02-08-2005, 4:46 AM
    • All-Star
      17,159 point All-Star
    • Dave Sussman
    • Member since 06-17-2002, 11:53 AM
    • UK
    • Posts 2,368
    • TrustedFriends-MVPs
    Because UserControls are automatically wrapped to make them WebParts you can't get direct access to the title without a little extra code. The first step is to implement the IWebPart interface yourself. In the code behind file simply add the interface:

    public partial class EditContactWebPart_ascx : Page, IWebPart

    or in VB

    Public Partial Class EditContactWebPart_ascx
    Inherits Page
    Implements IWebPart

    Once added you should get a tooltip type link at the beginning of IWebPart (underneath the I) which allows you to add the methods and properties for the interface. You can then simply set the title where you need to (Page_Load perhaps).

    Dave
  • Re: WebParts - Usercontrol - Title

    02-08-2005, 5:17 AM
    • All-Star
      29,644 point All-Star
    • Fredrik N
    • Member since 06-22-2002, 5:03 AM
    • Sweden
    • Posts 5,334
    • TrustedFriends-MVPs
    Yes, add a Title attribute to the control, or implement the IWebPart interface.

    Take a look at this post on my blog.
    /Fredrik Normén - fredrikn @ twitter

    ASPInsider

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
  • Re: WebParts - Usercontrol - Title

    02-08-2005, 8:07 AM
    • Participant
      805 point Participant
    • richy_roo
    • Member since 12-18-2004, 1:24 PM
    • Posts 161
    Thanks, thats exactly what i need.

  • Re: WebParts - Usercontrol - Title

    07-06-2005, 11:40 AM
    • Member
      330 point Member
    • stucker79
    • Member since 06-15-2005, 10:24 PM
    • Posts 71
    I just tried this on one of my user controls.  In design view, the title comes up fine.  I can access the title property, using intellisense, in the page load event, and i have set it, but it is still coming up "untitled [1]" when I run the project.  It doesn't matter if I am logged in or not.  Any ideas?
  • Re: WebParts - Usercontrol - Title

    07-06-2005, 2:47 PM
    • Member
      25 point Member
    • OmidD
    • Member since 06-24-2005, 9:29 PM
    • CA, USA
    • Posts 5

    After you have implemented IWebPart make sure that you initialize the value to something that you want. See code below

        private string description = "Loan details";
        string IWebPart.Description
        {
            get
            {
                return description;
            }
            set
            {
                description = value;
            }
        }

        private string subtitle = "";
        [Personalizable]
        [WebBrowsable]
        [WebDisplayName("Subtitle")]
        [WebDescription("Subtitle for this webpart.")]
        string IWebPart.Subtitle
        {
            get
            {
                return subtitle;
            }
        }

        private string title = "Loan";
        string IWebPart.Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
            }
        }

    .
    .
    .
    etc.

  • Re: WebParts - Usercontrol - Title

    07-06-2005, 9:17 PM
    • Member
      330 point Member
    • stucker79
    • Member since 06-15-2005, 10:24 PM
    • Posts 71
    Thank you, that did it!
Page 1 of 1 (7 items)