Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

User Control's Default Property Values do Not Appear In Properties Window

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonathan Wood - 07 Feb 2008 16:33 GMT
Below is a user control (ascx file) I created.

Everything works fine except, when I first place an instance of the control
on a form and look at the associated properties, my initial property values
appear blank. They only show a value if I enter a new value.

What is the trick to have my default property values appear in the
properties window?

Thanks.

Signature

Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

<%@ Control Language="C#" ClassName="HelpButton" %>

<script runat="server">

protected string _helpFile = "Help.aspx";
protected string _imageUrl = "Help.png";

public string HelpFile
{
 get { return _helpFile; }
 set { _helpFile = value; }
}

public string ImageURL
{
 get { return _imageUrl; }
 set { _imageUrl = value; }
}

protected void Page_Load(object sender, EventArgs e)
{
 RegisterClientScripts();
}

protected override void Render(HtmlTextWriter writer)
{
 base.Render(writer);

 // Render control
 writer.Write(String.Format("<input type=\"image\" src=\"{0}\" alt=\"Help\"
onclick=\"javascript:return ShowHelp('{1}');\" style=\"border-width:0px;\",
/>",
  ResolveUrl("~/Images/Help.jpg"), ResolveUrl("~/Help/" + HelpFile)));
}

protected void RegisterClientScripts()
{
 // Create client-side scripts to generate kilograms from pounds and vice
versa
 if (!Page.ClientScript.IsClientScriptBlockRegistered("ShowHelp"))
 {
  Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "ShowHelp",
   "function ShowHelp(url){" +
   "window.open(url, \"_blank\",
\"height=300,width=450,toolbar=no,status=no,menubar=no,location=no,scrollbars=yes\");"
+
   "return false;}", true);
 }
}

</script>

Manish - 07 Feb 2008 20:41 GMT
Hi Jonathan,

Please refer to the code below to create the CotnrolLibrary and then use it
in your App.

namespace WebControlLibrary1
{
    /// <summary>
    /// Summary description for WebCustomControl1.
    /// </summary>
    [DefaultProperty("Text"),
    ToolboxData("<{0}:PopupGreeting runat=server></{0}:PopupGreeting>")]
    public class PopupGreeting : System.Web.UI.Control
    {
        [Bindable(true),
        Category("Appearance"),
        DefaultValue("")]
        public string PopupMessage
        {
            get
            {
                // See if the item exists in the ViewState
                object popupMessage = this.ViewState["PopupMessage"];
                if (popupMessage != null)
                    return this.ViewState["PopupMessage"].ToString();
                else
                    return "Welcome to my Web site!";
            }

            set
            {
                // Assign the ViewState variable
                ViewState["PopupMessage"] = value;
            }
        }

        [Bindable(true),
        Category("Appearance"),
        DefaultValue("")]
        public bool Enabled
        {
            get
            {
                // See if the item exists in the ViewState
                object enabled = this.ViewState["Enabled"];
                if (enabled != null)
                    return (bool) this.ViewState["Enabled"];
                else
                    return true;
            }

            set
            {
                // Assign the ViewState variable
                ViewState["Enabled"] = value;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            string scriptKey = "intoPopupMessage:" + this.UniqueID;

            if (!Page.IsStartupScriptRegistered(scriptKey) && this.Enabled &&
                !Page.IsPostBack)
            {
                string scriptBlock =
                    @"<script language=""JavaScript"">
              <!--
                 alert(""%%POPUP_MESSAGE%%"");
              // -->
              </script>";
                scriptBlock = scriptBlock.Replace("%%POPUP_MESSAGE%%", this.PopupMessage);

                Page.RegisterStartupScript(scriptKey, scriptBlock);
            }
        }
    }

}

Regards,
Manish
www.ComponentOne.com

> Below is a user control (ascx file) I created.
>
[quoted text clipped - 6 lines]
>
> Thanks.
Jonathan Wood - 08 Feb 2008 00:26 GMT
Okay, looks like I may be missing a few elements. I'll print out your post
and do a bit more studying.

Thanks.

Signature

Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

> Hi Jonathan,
>
[quoted text clipped - 95 lines]
>>
>> Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.