Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 11th, 2009, 05:55 PM
Authorized User
 
Join Date: Dec 2008
Location: San Antonio, TX, USA.
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
Default Disappearing UserName & Question within Customized PasswordRecovery Question Template

Hello,

I am new to ASP.NET and C#, but slowly getting the hang of things. That said, I've run into a bit of a puzzle that I'm hoping someone can help me with.

I have a PasswordRecovery whose templates I have customized. Long story short: I loathe the nested-table-based layout in which it comes out of the box. So except for the actual form fields and labels themselves, everything went into DIVs with CSS classes.

All that went well except for the Question Template, where the UserName and Question values (not the labels) disappear. I have Googled several sites that show how to customize the PasswordRecovery tool and consulted a couple of ASP.NET books. My templates look identical to theirs.

When reset to their default appearance, these two values reappear, but then I'm back to that hideous nested-table layout, which will interfere with our Section 508-friendly policy. So I know the cause is wrapped up somewhere inside the Add Template function.

Below is my customized code:

Code:
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
 

<MailDefinition From="binky@somedomain.net" BodyFileName="~/App_Data/SignUpConfirmation.txt" />
<QuestionTemplate>
<div class="topbottompadding">Please answer your Secret Question.</div>
<table>
<tr>
<td class="right">User ID:</td>
<td><asp:Literal ID="UserName" runat="server"></asp:Literal></td>
</tr>
<tr>
<td class="right">Your Secret Question:</td>
<td><asp:Literal ID="Question" runat="server"></asp:Literal></td>
</tr>
<tr>
<td class="right"><asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Answer:</asp:Label></td>
<td>
<asp:TextBox ID="Answer" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer" ErrorMessage="Answer is required." ToolTip="Answer is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
</td>
</tr>
</table>
<div class="topbottompadding"><asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" /></div>
<div class="topbottompadding"><span class="boldred"><asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal></span></div>
</QuestionTemplate>
<UserNameTemplate>
<div class="topbottompadding">Please enter your User ID.</div>
<table>
<tr>
<td class="right"><asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User ID:</asp:Label></td>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User ID is required." ToolTip="User Id is required." ValidationGroup="PasswordRecovery1" CssClass="boldred">*</asp:RequiredFieldValidator>
</td>
</tr>
</table>
<div class="topbottompadding"><asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" CssClass="button" /></div>
<div class="topbottompadding"><span class="boldred"><asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal></span></div>
</UserNameTemplate>
<SuccessTemplate>
<div class="topbottompadding"><span class="boldred">Your password has been reset and emailed to you.</span></div>
</SuccessTemplate>
</asp:PasswordRecovery>
When I reach the Secret Question page, I get the following (sans CSS formatting; problem areas highlighted red):

Reset Password

Please answer your Secret Question.
User ID:
Your Secret Question:
Answer:

Your answer could not be verified. Please try again.

Can anyone please advise me? Thanks so much.
__________________
~ Eddie McHam
  #2 (permalink)  
Old June 12th, 2009, 01:11 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

When you use a template like this, the values do not just magically appear. You have to bind them yourself.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #3 (permalink)  
Old June 12th, 2009, 02:21 PM
Authorized User
 
Join Date: Dec 2008
Location: San Antonio, TX, USA.
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thank you for confirming what I already suspected. For some reason, none of the QuestionTemplate samples or tutorials covered that part. All they showed were two literals with IDs "UserName" and "Question."

So I've managed to scrape up some C# code and gotten the UserName to finally show up. I'm still having quite a time pulling up the PasswordRecovery.Question.

Here is the C# code I've got so far:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class_Default : System.Web.UI.Page

{ 
protected void Page_Load(object sender, EventArgs e)
{
TextBox userID = (TextBox)PasswordRecovery1.UserNameTemplateContainer.FindControl("UserName");
userID.Focus();
Literal qUserName = (Literal)PasswordRecovery1.QuestionTemplateContainer.FindControl("UserName");
qUserName.Text = userID.Text;
Literal secretQuestion = (Literal)PasswordRecovery1.QuestionTemplateContainer.FindControl("Question");
secretQuestion.Text = PasswordRecovery1.Question;
}
}
Again, I apologize for such a newbie question and appreciate any additional tips.

~e
__________________
~ Eddie McHam
  #4 (permalink)  
Old June 12th, 2009, 03:19 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Sorry, I think I answered your question too flippantly the first time. My apologies.

I looked more closely to see what you did in your template. Actually, because of the names you have given to the controls, they SHOULD bind automatically. My bad for telling you otherwise.

I actually tried your exact template on my end and it worked ok.

Do me a favor. Disable all of your CSS and try it again.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #5 (permalink)  
Old June 12th, 2009, 03:36 PM
Authorized User
 
Join Date: Dec 2008
Location: San Antonio, TX, USA.
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Sorry, no luck.

I removed the CSS classes from the QuestionTemplate DIVs and commented out my CSS links in the master page so that all XHTML shows up as plain-jane.

Question didn't show up. I even double-checked the HTML in View Source. It's an empty table cell.

I did, however, figure out how in C# to pull up the UserName, going by your earlier post about binding that literal's Text property. That's working now.

It's the PasswordQuestion property that's still throwing me for a loop, and I still haven't found a C# tutorial that explains it well enough for a total n00b like me to figure out....and I do like to think I'm a pretty quick study.

~e
__________________
~ Eddie McHam
  #6 (permalink)  
Old June 12th, 2009, 03:50 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Very weird, as I told you, I set up a quickie membership site on my end and used your exact template and it worked for me. You might want to try that.

The other thing I would STRONGLY suggest is to inspect the output with Firebug. That will tell you if the controls are bing rendered but are hidden for some reason, or if they just aren't rendering at all.

Anyway, the way to get at the Secret Question, given the user name, is as follows:

Code:
string question = Membership.GetUser("theUserName").PasswordQuestion;
Hope that helps.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}

Last edited by Lee Dumond; June 12th, 2009 at 03:51 PM.. Reason: typo
  #7 (permalink)  
Old June 12th, 2009, 04:18 PM
Authorized User
 
Join Date: Dec 2008
Location: San Antonio, TX, USA.
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
Default

THANK YOU!!!!!

Added your passwordquestion line, and at first it didn't work, no matter how many times I rebuilt the page. At some point, I wound up back at the UserName page, re-entered my User Name, and the Question finally showed up.

I guess somehow the UserName value got lost in all the editing and rebuilding. VWD is not very good at refreshing everything......nor is IE8.

But at last the silly thing is functional, and I get to keep my table-less templates. I do appreciate your help very much.

Have a great weekend. I know I shall.

~e
__________________
~ Eddie McHam
  #8 (permalink)  
Old June 12th, 2009, 04:24 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Okay. don't forget to click the Thanks button. --->

I need the karma. :D
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
eddiemcham (June 12th, 2009)
  #9 (permalink)  
Old June 12th, 2009, 04:31 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi eddie,

If table-less design (or less tables) is your main goal, you may also want to take a look at the CSS Control Adapters. They allow you to alter the markup of some default controls to use divs instead of tables:

http://www.asp.net/CSSAdapters/Default.aspx
http://www.asp.net/CSSAdapters/Membe...serWizard.aspx

Cheers,

Imar
---------------------------------------------------------------------------------------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
While typing this post, I was listening to: Julien by Placebo (Track 9 from the album: Battle For The Sun) What's This?
  #10 (permalink)  
Old June 12th, 2009, 04:35 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by Imar View Post
Hi eddie,

If table-less design (or less tables) is your main goal, you may also want to take a look at the CSS Control Adapters. They allow you to alter the markup of some default controls to use divs instead of tables:

http://www.asp.net/CSSAdapters/Default.aspx
http://www.asp.net/CSSAdapters/Membe...serWizard.aspx
Was gonna actually suggest this, but unfortunately the CSS control adapters do NOT work well for the Membership controls. If you look at the CodePlex there are lots and lots of unresolved bugs on that.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
Imar (June 12th, 2009)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about template precedence asc BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 3 December 1st, 2008 08:14 AM
Question on Apply Template vvenk XSLT 7 July 10th, 2008 12:21 PM
Datagrid Item Template question dparsons ASP.NET 1.0 and 1.1 Professional 3 March 14th, 2007 09:08 AM
Template Column - question vox ASP.NET 1.0 and 1.1 Basics 2 June 7th, 2005 11:53 AM
ASP datagrid template textbox question chas036 ASP.NET 1.x and 2.0 Application Design 1 December 29th, 2003 04:01 PM



All times are GMT -4. The time now is 02:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.