locked
Doesn't remember properties set programatically RRS feed

  • Question

  • User-879100993 posted

     Trying to create a clickable image with mouseout image as a custom control.

    Problem is : when I set all properties on the aspx page, everything works fine, but when I try the same properties programatically - even though the control accepts it, but does not reflect the values. They are always empty.

     

    Here is what works properly:

     

    <wiz1:hoverimagelink runat="<span" class="st">"Server" ID="HoverLink1" ImageUrl="~/img/but-takeaction2.jpg"  ImageHoverUrl="~/img/but-takeaction1.jpg" /> </wiz1:hoverimagelink>
      

    But when I try it programatically on postback like the following line, it fails:

     

    HoverLink1.ImageHoverUrl = "~/img/but-takeaction1.jpg";
     

    The output comes something like this in this case:

     
    "HoverLink1" onmouseover="ShowImageHoverButton(this, '')" onmouseout="ShowImageHoverButton(this, '/wiz.net/WizLibrary/img/but-takeaction2.jpg')" 
    onclick="window.location=''" src="/wiz.net/WizLibrary/img/but-takeaction2.jpg" style="border-width: 0px; cursor: pointer;">

     

    I have unsuccessfully tried setting attributes like "PersistenceMode, Bindable, Localizable" and so on but it simply fails to get the value. 

     For any of you who need to know, how I define the properties themselves, here's one of them:

     

     [Bindable(true)]
    [Category("Appearance")]
    [DefaultValue("")]
    [Localizable(false)]
    [PersistenceMode( PersistenceMode.Attribute)]
    [UrlProperty(), Editor("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)), Themeable(false)]
    public string ImageHoverUrl
    {
    get
    {
    this.EnableViewState = true;
    String s = (String)ViewState["ImageHoverUrl"];
    return ((s == null) ? String.Empty : s);
    }

    set
    {
    ViewState["ImageHoverUrl"] = value;
    }
    }
     
     

     

    Friday, June 6, 2008 5:33 AM

All replies

  • User-1187166364 posted

    public string ImageHoverUrl
    {
    get
    {
    this.EnableViewState = true;
    String s = (String)ViewState["ImageHoverUrl"];
    return ((s == null) ? String.Empty : s);
    }

    set
    {
    ViewState["ImageHoverUrl"] = value;
    }

     public string ImageHoverUrl
            {
                get
                {
                                   return ((ViewState["ImageHoverUrl"] == null) ? "defaultImage.jpg":ViewState["ImageHoverUrl"].ToString());
                }

                set
                {
                    ViewState["ImageHoverUrl"] = value;
                }

     

    Friday, June 6, 2008 6:25 AM
  • User-879100993 posted

     Well, I am also doing the same thing, except there's an extra line on my code that you can see (this.EnableViewState = true;) , but it doesnt affect anything - my code does not work, even without it - I tried. Your code is doing exactly same stuff as me. But just to make sure, I ran your code as well, and it fails.

     

    To reiterate, the problem really is that, setting properties on aspx page directly works, but not programatically. Here's the example that does not work:

     

        protected void Page_Load(object sender, EventArgs e)
    {
    HoverLink1.ImageHoverUrl = "~/img/but-takeaction1.jpg";
    if(!IsPostBack)
    HoverLink1.NavigateUrl = "~/default.aspx";
    }
      
    Friday, June 6, 2008 6:42 AM