|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |
|

June 11th, 2009, 06:55 PM
|
|
Authorized User
|
|
Join Date: Dec 2008
Location: San Antonio, TX, USA.
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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
|

June 12th, 2009, 02:11 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 803
Thanks: 12
Thanked 139 Times in 139 Posts
|
|
When you use a template like this, the values do not just magically appear. You have to bind them yourself.
|

June 12th, 2009, 03:21 PM
|
|
Authorized User
|
|
Join Date: Dec 2008
Location: San Antonio, TX, USA.
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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
|

June 12th, 2009, 04:19 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 803
Thanks: 12
Thanked 139 Times in 139 Posts
|
|
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.
|

June 12th, 2009, 04:36 PM
|
|
Authorized User
|
|
Join Date: Dec 2008
Location: San Antonio, TX, USA.
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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
|

June 12th, 2009, 04:50 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 803
Thanks: 12
Thanked 139 Times in 139 Posts
|
|
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.
Last edited by Lee Dumond : June 12th, 2009 at 04:51 PM.
Reason: typo
|

June 12th, 2009, 05:18 PM
|
|
Authorized User
|
|
Join Date: Dec 2008
Location: San Antonio, TX, USA.
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
 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
|

June 12th, 2009, 05:24 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 803
Thanks: 12
Thanked 139 Times in 139 Posts
|
|
Okay. don't forget to click the Thanks button. --->
I need the karma. :D
|
|
The Following User Says Thank You to Lee Dumond For This Useful Post:
|
|

June 12th, 2009, 05:31 PM
|
 |
Wrox Author
Points: 33,167, Level: 79 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,160
Thanks: 7
Thanked 188 Times in 186 Posts
|
|
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?
|

June 12th, 2009, 05:35 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 803
Thanks: 12
Thanked 139 Times in 139 Posts
|
|
Quote:
Originally Posted by Imar
|
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.
|
|
The Following User Says Thank You to Lee Dumond For This Useful Post:
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |