Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem in HtmlTextWriterAttribute.Value

Posted on 2009-05-13
7
Medium Priority
?
330 Views
Last Modified: 2013-11-08
Hi

I have created a class inherited from TextBox class

In that class I have override the Render function

see code

Now I am using this control dll in some other project

When I set the property MTBText I am not able to see the value on the webpage

Am I missing something
protected override void Render(HtmlTextWriter output)
        {
            output.RenderBeginTag(HtmlTextWriterTag.Input);
            output.AddAttribute(HtmlTextWriterAttribute.Type, "text");
            output.AddAttribute(HtmlTextWriterAttribute.Name, this.ClientID);
            output.AddAttribute(HtmlTextWriterAttribute.Value, MTBText);            
            output.RenderEndTag();
}

Open in new window

0
Comment
Question by:KaranGupta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24373121
can you post your MTBText property definition?
0
 

Author Comment

by:KaranGupta
ID: 24373131
here we go
 protected override void Render(HtmlTextWriter output)
        {
            output.RenderBeginTag(HtmlTextWriterTag.Input);
            output.AddAttribute(HtmlTextWriterAttribute.Type, "text");
            output.AddAttribute(HtmlTextWriterAttribute.Id, MTBID);
            output.AddAttribute(HtmlTextWriterAttribute.Value, MTBText);
            output.RenderEndTag();
           // base.Render(output);           
           
 
        }
 
 
        /// <summary>
        /// Text
        /// </summary>
        public string MTBText
        {
            get;
            set;
        }

Open in new window

0
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24373154
in the MTBText property are you using the viewstate? kind of like this:
		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("")]
		[Localizable(true)]
		public string Text
		{
			get
			{
				String s = (String)ViewState["Text"];
				return ((s == null) ? "[" + this.ID + "]" : s);
			}
 
			set
			{
				ViewState["Text"] = value;
			}
		}

Open in new window

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

Author Comment

by:KaranGupta
ID: 24373181
This definition of Text was given earlier when I created the project

But I have commented the definition
0
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24373218
yes - but does your MTBText property work in the same way so that the value is stored in the viewstate properly and can be rendered? If you put a break point in your rendering code does the MTBText property have a value?
0
 

Author Comment

by:KaranGupta
ID: 24373278
Hi

I am attaching the whole code

Please look into it

And this is how I am calling this control

<FTB:MultiPurposeTextControl MTBErrorMessageControlType="VALIDATIONSUMMARY" MTBText="karan" MTBID="test" runat="server"></FTB:MultiPurposeTextControl>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace MultiPurposeTextBox
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]
    public class MultiPurposeTextControl : WebControl
    {
        
        protected override void Render(HtmlTextWriter output)
        {
            output.RenderBeginTag(HtmlTextWriterTag.Input);
            output.AddAttribute(HtmlTextWriterAttribute.Type, "text");
            output.AddAttribute(HtmlTextWriterAttribute.Id, MTBID);
            output.AddAttribute(HtmlTextWriterAttribute.Value, MTBText);
            output.RenderEndTag();
           // base.Render(output);           
           
 
        }
 
 
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string MTBText
        {
            get
            {
                String s = (String)ViewState["Text"];
                return ((s == null) ? "[" + this.ID + "]" : s);
            }
 
            set
            {
                ViewState["Text"] = value;
            }
        }
      
        /// <summary>
        /// ID
        /// </summary>
        public string MTBID
        {
            get;
            set;
        }
 
        /// <summary>
        ///   Property to specify whether you want to 
        ///   give error message to a label or want to
        ///   integrate it with validation summary
        /// </summary>       
        public MTBErrorMessageControl MTBErrorMessageControlType
        {
            get;
            set;
        }
 
 
        /// <summary>
        ///   Property to specify what sort of validation
        ///   you want 
        /// </summary> 
        public MTBValidation MTBValidationType
        {
            get;
            set;
        }
 
        /// <summary>
        /// Enums for different Types of validation
        /// </summary>
        public enum MTBValidation
        {
            INTEGER,
            ALPHABET
        }
 
        /// <summary>
        /// Enums for different Types of controls
        /// on which you want to show error message
        /// </summary>
        public enum MTBErrorMessageControl
        {
            LABEL,
            VALIDATIONSUMMARY
        }
 
    }
}

Open in new window

0
 
LVL 12

Accepted Solution

by:
GuitarRich earned 2000 total points
ID: 24373382
ok - this is what I have got - is this closer. I realised the mistake with the MTBText, you need to add the attributes before the RenderBeginTag call - sorry got it the wrong way wrond earlier.
		/// <summary>
		/// Enums for different Types of controls
		/// on which you want to show error message
		/// </summary>
		public enum MTBErrorMessageControl
		{
			LABEL,
			VALIDATIONSUMMARY
		}
 
 
		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("")]
		[Localizable(true)]
		public string MTBText
		{
			get
			{
				String s = (String)ViewState["MTBText"];
				return ((s == null) ? "[" + this.ID + "]" : s);
			}
 
			set
			{
				ViewState["MTBText"] = value;
			}
		}
 
		/// <summary>
		///   Property to specify whether you want to 
		///   give error message to a label or want to
		///   integrate it with validation summary
		/// </summary>       
		public MTBErrorMessageControl MTBErrorMessageControlType
		{
			get
			{
				if (ViewState["MTBErrorMessageControlType"] == null)
				{
					return MTBErrorMessageControl.LABEL;
				}
				else
				{
					MTBErrorMessageControl s = (MTBErrorMessageControl)ViewState["MTBErrorMessageControlType"];
					return s;
				}
			}
 
			set
			{
				ViewState["MTBErrorMessageControlType"] = value;
			}
		}
 
 
		protected override void Render(HtmlTextWriter writer)
		{
			//base.Render(writer);
			writer.RenderBeginTag(HtmlTextWriterTag.Span);
 
			writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
			writer.AddAttribute(HtmlTextWriterAttribute.Name, this.ClientID);
			writer.AddAttribute(HtmlTextWriterAttribute.Value, this.Text);
			writer.RenderBeginTag(HtmlTextWriterTag.Input);
 
			writer.RenderEndTag();
 
			if (this.MTBText != string.Empty && this.MTBErrorMessageControlType == MTBErrorMessageControl.LABEL)
			{
				writer.AddAttribute(HtmlTextWriterAttribute.For, this.ClientID);
				writer.RenderBeginTag(HtmlTextWriterTag.Label);
 
				writer.Write(this.MTBText);
				writer.RenderEndTag();
			}
 
			writer.RenderEndTag(); // span
		}

Open in new window

0

Featured Post

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question