• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 584
  • Last Modified:

Rendering Complete Start and End Tags for INPUT in Custom Control

I am writing a custom button control (inherited from the ASP.NET button) that inserts SPAN tags between the tags of the rendered INPUT element.

The issue I am having is that when the control is rendered the INPUT element is always automatically closed.

<INPUT ... />

I need the INPUT to be rendered with a full start and end tag so that my SPAN element is properly placed.

<INPUT ...><SPAN ...></SPAN></INPUT>


public override void RenderBeginTag(HtmlTextWriter writer)
{
    base.RenderBeginTag(writer);
}
 
protected override void RenderContents(HtmlTextWriter writer)
{
    writer.WriteBeginTag("span");
    writer.WriteAttribute("class", this.ButtonCssClass);
    writer.Write(HtmlTextWriter.TagRightChar);
    base.RenderContents(writer);
    writer.WriteEndTag("span");
}
 
public override void RenderEndTag(HtmlTextWriter writer)
{
    base.RenderEndTag(writer);
}

Open in new window

0
hehdaddy
Asked:
hehdaddy
  • 4
  • 3
1 Solution
 
daveamourCommented:
Are span tags allowed inside input tags within html?
What is it you are actually trying to achieve?
0
 
hehdaddyAuthor Commented:
It would be rendered similar to this:  <INPUT TYPE="BUTTON" CLASS="ROUND" ...><SPAN>Button Text</SPAN></INPUT>

CSS styles and an image are used to make this a button with rounded ends.
0
 
daveamourCommented:
I see
Can you show me all of your button control code?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
hehdaddyAuthor Commented:
My button control code is just inheriting from System.Web.UI.* Button control. The three methods I listed are the only ones that deal with the rendering.

I did find an optional solution, and that was to inherit from the LinkButton control, spitting out the SPAN tags, etc., that I needed.

I am thinking that the only real solution for my question above, is to completely override the rendering methods and generate all the markup in my code.
0
 
daveamourCommented:
I don't think you are going to get this working with a button.
I tried just writing one in plain HTML to see how the browser would render it and I wrote this:
<input type="button"><span>Click Me</span></button>
And it rendered the button and the Click me came after the button.  I suspect this isn't in the html standard so maybe best to use a different control as your base control?
0
 
hehdaddyAuthor Commented:
Thanks for your help. My work in using the Link Button control worked like a charm.
0
 
daveamourCommented:
Ok thanks for the points
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now