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.