About two months ago, I wrote a post about removing the TABLE from ASP.Net 2.0’s Login control. The below code will let you do the same from the CreateUserWizard
control. One important caveat: for this to work (in my limited testing), you must provide a custom template for the ContentTemplate
and CustomNavigationTemplate
of the CreateUserWizardStep
, and for the ContentTemplate
of the CompleteWizardStep
.
public class CssCreateUserWizard : System.Web.UI.WebControls.CreateUserWizard { protected override void Render( HtmlTextWriter writer ) { if ( CreateUserStep.ContentTemplate != null && this.ActiveStep == this.CreateUserStep ) { WebControl creatediv = new WebControl( HtmlTextWriterTag.Div ); creatediv.CssClass = this.CssClass; CreateUserStep.ContentTemplate.InstantiateIn( creatediv ); CreateUserStep.ContentTemplateContainer.Controls.Clear(); CreateUserStep.ContentTemplateContainer.Controls.Add( creatediv ); creatediv.RenderControl( writer ); if ( CreateUserStep.CustomNavigationTemplate != null ) { WebControl navdiv = new WebControl(HtmlTextWriterTag.Div); navdiv.CssClass = this.CssClass; CreateUserStep.CustomNavigationTemplate.InstantiateIn(navdiv); CreateUserStep.CustomNavigationTemplateContainer.Controls.Clear(); CreateUserStep.CustomNavigationTemplateContainer.Controls.Add(navdiv); navdiv.RenderControl(writer); } } if ( CompleteStep.ContentTemplate != null && this.ActiveStep == this.CompleteStep ) { WebControl completediv = new WebControl( HtmlTextWriterTag.Div ); completediv.CssClass = this.CssClass; CompleteStep.ContentTemplate.InstantiateIn( completediv ); CompleteStep.ContentTemplateContainer.Controls.Clear(); CompleteStep.ContentTemplateContainer.Controls.Add( completediv ); completediv.RenderControl( writer ); } } }
Kevin says:
Hey, this is a great article. I’m looking to do this exact thing. It’s been a while since you wrote this article so I’m wondering if you’ve had any more insights.
I using this code but when I do, nothing shows up. I did add the customtemplate and CustomNavigationTemplate (with nothing in them). Is that sufficient? Also, is the CompleteWizardStep node required?
Thanks in advance.
brian says:
I would try the following, which I’ve used rather successfully on quite a few sites. Note that this will strip any HTML TABLEs from your markup, so don’t use any in your templates.
Kevin says:
I’m no regex expert, but, the remove tables seems to do the same thing over and over again. It doesn’t remove the table, but it does remove the closing tags within my wizard and this causes a world of problems. I’m assuming the regex stuff should be more related to “table tag” stuff like table, tr, td, th, tbody. ? Am I on the right track?
brian says:
Text got stripped out when the post was made, let me fix it…
OK, should be better now. Damn web editors!
Kevin says:
Actually… I think I got it. I changed the regex stuff to this:
str = Regex.Replace(str, “]*>|]*>|]*>|]*>|]*>”, String.Empty);
Seems to work great now! Thanks for all the help.
Kevin says:
oooooh interesting… I just pasted my code and it appears your parser is removed the valuable syntax. I see the problem now. I’ll past it again with a space between each char. This will only be the actual regex string.
] * > | ] * > | ] * > | ] * > | ] * >
Kevin says:
dang… that’s sneaky… I couldn’t even do it like that.. I’ll try replacing the code with html safe values. If this doesn’t work, I’ll stop comment spamming:
</?table[^>]*>|</?tr[^>]*>|</?td[^>]*>|</?thead[^>]*>|</?tbody[^>]*>
brian says:
The regex is now correct in my previous comment. Basically, it strips out TABLE, THEAD, TBODY, TR, and TD tags, which are those created by the CreateUserWizard adapter. You can use the same regex patterns with TFOOT, COLGROUP, COL, and TH to be more thorough (though it’s unnecessary as they are not used).
RA says:
“Create user” button is disappeared
RA says:
replace
base.RenderContents(hw);
on
base.Render(hw);