Sorry if this has been asked before. I have been trawling the forums for hours now to no avail.
I have added a usercontrol as a forgot password option. There are a couple of problems. First when I used an asp:Button the onclick event would not fire at all. Second I worked around this by using a link button. This enabled on click event to fire, however the postback event seems to lose the textbox value. When I debug the onclick event the textbox value is blank.
I have the content within a form runat=server tag. The code for the control is below
ACSX.CS
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco;
using umbraco.cms.businesslogic.member;
public partial class ForgotPassword : UserControl
{
// Error format
private const string ErrorFormat = "
{0}
";
// From Email Address
private const string FromEmail = "[email protected]";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void BtnSubmitClick(object sender, EventArgs e)
{
// Try and get the member from the email address entered
var cMember = Member.GetMemberFromEmail(tbEmail.Text);
// Check we have a member with that email address
if (cMember != null)
{
// Found the user
// Generate a password which we'll email the member
var password = Membership.GeneratePassword(10, 1);
password = Regex.Replace(password, @"[^a-zA-Z0-9]", m => "9");
// Change the password to the new generated one above
var member = Membership.GetUser(cMember.LoginName);
member.ChangePassword(member.ResetPassword(), password);
// Save the password/member
cMember.Save();
// update the XML cache
cMember.XmlGenerate(new System.Xml.XmlDocument());
// Now email the member their password
var sb = new StringBuilder();
sb.AppendFormat(string.Format("<p>Please find your new password below to access the site</p>"));
sb.AppendFormat("<p><b>{0}</b></p>", password);
library.SendMail(FromEmail, cMember.Email, "Password Reset", sb.ToString(), true);
// Disable the button to stop them pressing it again
// btnSubmit.Enabled = false;
// Show a message to the user
litError.Text = string.Format(ErrorFormat, "Password Sent");
}
else
{
// Can't find a user with that email
litError.Text = string.Format(ErrorFormat, "Can't find a user with that email address");
}
}
I am using umbraco 6.1.6, I built the control in VS2010 and then copied the ascx and cs to the user controls folder. I noticed that if I change the asp:button to an asp:LinkButton it works sucessfully
User Control Postback
Sorry if this has been asked before. I have been trawling the forums for hours now to no avail.
I have added a usercontrol as a forgot password option. There are a couple of problems. First when I used an asp:Button the onclick event would not fire at all. Second I worked around this by using a link button. This enabled on click event to fire, however the postback event seems to lose the textbox value. When I debug the onclick event the textbox value is blank.
I have the content within a form runat=server tag. The code for the control is below
ACSX.CS using System; using System.Text; using System.Text.RegularExpressions; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using umbraco; using umbraco.cms.businesslogic.member;
public partial class ForgotPassword : UserControl { // Error format private const string ErrorFormat = "
{0}
";}
Hi Colin
There are many reasons why your code might be failing, can you give some background to your build?
What version of Umbraco are you using?
Did you build your control in Visual Studio as a web project or website?
Have you deployed your DLL in the BIN folder or added the .cs to app_code?
Kind regards
Martin
Hi Martin,
I am using umbraco 6.1.6, I built the control in VS2010 and then copied the ascx and cs to the user controls folder. I noticed that if I change the asp:button to an asp:LinkButton it works sucessfully
is working on a reply...