Link to home
Start Free TrialLog in
Avatar of deersuper
deersuper

asked on

Another question about custom controls

I am using the Wrox book for custom controls.

I am using their examples and everything they have in their examples works just fine but if I make slight additions to the code I dont see the change I have made being reflected.

my code is as given below (the portion I made I will indicate):

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace TestControlNameSpace2
{
      /// <summary>
      /// Summary description for WebCustomControl1.
      /// The Client Web Form is Called TestControlClient2.aspx
      /// </summary>
      [DefaultProperty("Text"),
      ToolboxData("<{0}:TestControl2 runat=server></{0}:TestControl2>")]
      public class TestControl2 : System.Web.UI.WebControls.WebControl
      {
            private string text;
            private string message;
            private string anotherMessage;    -------> I ADDED TO THE BOOKS CODE
            [Bindable(true),
            Category("Appearance"),
            DefaultValue("")]
            public string Text
            {
                  get
                  {
                        return text;
                  }

                  set
                  {
                        text = value;
                  }
            }
            [Bindable(true),Category("Misc")]
            public string ExMessage
            {
                  get{return message;}
                  set {message=value;}
            }
            [Bindable(true),Category("Misc")]             ----------------------------------------------------------------->
            public string AnotherMessage                  |
            {                                                          |
                  get{return anotherMessage;}  |    EVERYTHING I ADDED
                  set{anotherMessage=value;}   |
            }                                                            |----------------------------------------------------------------->

            /// <summary>
            /// Render this control to the output parameter specified.
            /// </summary>
            /// <param name="output"> The HTML writer to write out to </param>
            protected override void Render(HtmlTextWriter output)
            {
                  output.Write(text+" "+message+" "+anotherMessage); ----->anotherMessage I Added
            }
      }
}

I hope my code is clear to understand and now for the problem ....
I added string anotherMessage and its accessor and setter method WHICH IS EXACTLY LIKE THE ExMessage method.
I basically copied the ExMessage code for AnotherMessage and in Render method I added anotherMessage as a part of the string.

It does not work.... I am surprised WHY ? I didnt do anything fancy here ... just copy paste.
Without the anotherMessage everything looks and works great !
What do you think ?
Avatar of raterus
raterus
Flag of United States of America image

Can you show the code you are using in your aspx page to set values in the control.  What exactly isn't working too, error, blank text?
Avatar of deersuper
deersuper

ASKER

the code that is not working is :

<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<cc1:TestControl2 id="TestControl22" runat="server" Text="rrrr" AnotherMessage="wwww" ExMessage="eeee"></cc1:TestControl2></form>
</body>

Text = "rrr" renders so does ExMessage but AnotherMessage does not.

and from the .cs file code I have provided it is clear that AnotherMessage is like a twin of the ExMessage.
ASKER CERTIFIED SOLUTION
Avatar of praneetha
praneetha

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I figured out the problem ! the updated control was not being added to the control list !
I had to manually remove reference to the control and then also remove it from toolbox and re do these 2 steps again.

Worked fine then !

ur answer showed up later after I had posted my comments but what you say is exactly what the problem is !

thanks ... I ll have another question about custom controls soon..... lol :)