Please disable your adblock and script blockers to view this page
 

Create registration form and send confirmation email to new registered users in asp.net | Activate or approve user account by activation link in email address.

Introduction: In this article I am going to explain with example How to create registration form and approve newly registered user by sending them account activation link on their email address in asp.net with both C#.Net and VB.Net languages.

Activate user account using activate link in email address using asp.net

Description: The concept is simple as mentioned below.
  1. First user will fill the form having Name, Email Id, Address and Contact Number field. This information will be stored in the Sql server database table where a field “Is_Approved” is set to 0 i.e. false by default. 
  2. Also email id, and the user id based on email id is set in the query string parameters and sent to the email address of the newly registered user as an activation link. 
  3. When user check his email and click on the activation link then he will be redirected to the "ActivateAccount.aspx" page where User id and email Id from the query string will be verified and the “Is_Approved” field in the sql server table is set to 1 i.e. True. 
  4. Now he is an approved user and authorized to log in.
Implementation: let’s create an asp.net web application to understand the concept.
Click on the image  to enlarge
First of all create a database e.g. “MyDataBase” in Sql server and create a table with the column and the data type as shown and name it “Tb_Registration”

Note: I have set the data type of the Is_Approved field to bit and set its default value to 0 i.e. false. It means whenever a new record is inserted in the table the “Is_Approved” will be 0. So the new users need to get their account approved by clicking on the activation link in their email address.

  • In the web.config file create the connection string to connect your asp.net application to the Sql server database as:
<connectionStrings>
    <add name="conStr" connectionString="Data Source=lalit;Initial Catalog=MyDataBase;Integrated Security=True"/>
  </connectionStrings>

Note: Replace the Data Source and Initial Catalog(i.e. DataBase Name) as per your application.

Source Code:
  • Add a page and name it “Registration.aspx” and design the page as:
<div>
    <fieldset style="width:350px;">
    <legend>Registeration page</legend>   
    <table>
    <tr>
    <td>Name *: </td><td>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br /><asp:RequiredFieldValidator
            ID="rfvName" runat="server" ErrorMessage="Please enter Name"
            ControlToValidate="txtName" Display="Dynamic" ForeColor="#FF3300"
            SetFocusOnError="True"></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td>Email Id: * </td><td>
        <asp:TextBox ID="txtEmailId" runat="server"></asp:TextBox><br />
        <asp:RequiredFieldValidator ID="rfvEmailId" runat="server"
            ControlToValidate="txtEmailId" Display="Dynamic"
            ErrorMessage="Please enter Email Id" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="rgeEmailId" runat="server"
            ControlToValidate="txtEmailId" Display="Dynamic"
            ErrorMessage="Please enter valid email id format" ForeColor="Red"
            SetFocusOnError="True"
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        </td>
    </tr>
    <tr>
    <td>Address : </td><td>
        <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
    <td>Contact No.</td><td>
        <asp:TextBox ID="txtContactNo" runat="server"></asp:TextBox></td>
    </tr>
        <tr>
    <td>&nbsp;</td><td>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit"
                onclick="btnSubmit_Click" /></td>
    </tr>
    </table>
    </fieldset>
    </div>

Note: I have also implemented the validation on Name and the Email Id field to ensure they are not left blank using RequiredFieldValidator validation control and also used RegularExpressionValidator to check for the valid email address on the Email Id field.

Asp.Net C# Code for Registration.aspx
  • In the code behind file (Registration.aspx.cs) write the code as:
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using System.Net;
using System.Net.Mail;

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        MailMessage msg;     
        SqlCommand cmd = new SqlCommand();
        string ActivationUrl = string.Empty;
        string emailId = string.Empty;
        try
        {
            cmd = new SqlCommand("insert into Tb_Registration (Name,EmailId,Address,ContactNo) values (@Name,@EmailId,@Address,@ContactNo) ", con);
            cmd.Parameters.AddWithValue("@Name", txtName.Text.Trim());
            cmd.Parameters.AddWithValue("@EmailId", txtEmailId.Text.Trim());
            cmd.Parameters.AddWithValue("@Address", txtAddress.Text.Trim());
            cmd.Parameters.AddWithValue("@ContactNo", txtContactNo.Text.Trim());
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            cmd.ExecuteNonQuery();
        //Sending activation link in the email
            msg = new MailMessage();
            SmtpClient smtp = new SmtpClient();
            emailId = txtEmailId.Text.Trim();
            //sender email address
            msg.From = new MailAddress("YourGmailEmailId@gmail.com");          
            //Receiver email address
            msg.To.Add(emailId);
            msg.Subject = "Confirmation email for account activation";
            //For testing replace the local host path with your lost host path and while making online replace with your website domain name
            ActivationUrl = Server.HtmlEncode("http://localhost:8665/MySampleApplication/ActivateAccount.aspx?UserID=" + FetchUserId(emailId) + "&EmailId=" + emailId);

            msg.Body = "Hi " + txtName.Text.Trim() + "!\n" +
                  "Thanks for showing interest and registring in <a href='http://www.webcodeexpert.com'> webcodeexpert.com<a> " +
                  " Please <a href='" + ActivationUrl + "'>click here to activate</a>  your account and enjoy our services. \nThanks!";
            msg.IsBodyHtml = true;
            smtp.Credentials = new NetworkCredential("YourGmailEmailId@gmail.com", "YourGmailPassword");
            smtp.Port = 587;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            smtp.Send(msg);
            clear_controls();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Confirmation Link to activate your account has been sent to your email address');", true);
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
            return;
        }
        finally
        {
            ActivationUrl = string.Empty;
            emailId = string.Empty;
            con.Close();
            cmd.Dispose();
        }
    }  

    private string FetchUserId(string emailId)
    {
        SqlCommand cmd = new SqlCommand();
        cmd = new SqlCommand("SELECT UserId FROM Tb_Registration WHERE EmailId=@EmailId", con);
            cmd.Parameters.AddWithValue("@EmailId", emailId);
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            string UserID = Convert.ToString(cmd.ExecuteScalar());
            con.Close();
            cmd.Dispose();
            return UserID;
        }

    private void clear_controls()
    {
        txtName.Text = string.Empty;
        txtEmailId.Text = string.Empty;
        txtAddress.Text = string.Empty;
        txtContactNo.Text = string.Empty;
        txtName.Focus();
    }

  • Add a new page and name it “ActivateAccount.aspx”. This page will be opened when new registered user click on the activate account link in his email. On the page load it will check email id and user id from the query string and then update the "Is_Approved" column to 1 i.e. True. Then you can redirect him to your login page to log in.

Code for ActivateAccount.aspx page
  • In the code behind file (ActivateAccount.aspx.cs) write the code as:
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ActivateMyAccount();
        }
    }

    private void ActivateMyAccount()
    {
        SqlConnection con = new SqlConnection();
        SqlCommand cmd = new SqlCommand();
        try
        {
            con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);

            if ((!string.IsNullOrEmpty(Request.QueryString["UserID"])) & (!string.IsNullOrEmpty(Request.QueryString["EmailId"])))
            {   //approve account by setting Is_Approved to 1 i.e. True in the sql server table
                cmd = new SqlCommand("UPDATE Tb_Registration SET Is_Approved=1 WHERE UserID=@UserID AND EmailId=@EmailId", con);
                cmd.Parameters.AddWithValue("@UserID", Request.QueryString["UserID"]);
                cmd.Parameters.AddWithValue("@EmailId", Request.QueryString["EmailId"]);
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                cmd.ExecuteNonQuery();
                Response.Write("You account has been activated. You can <a href='Login.aspx'>Login</a> now! ");
            }
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
            return;
        }
        finally
        {
            con.Close();
            cmd.Dispose();
        }
    }

Asp.Net VB Section:

Source code of Registration.aspx
  • Design the Registration.aspx page as in C#.Net section but replace the line 
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" /> With <asp:Button ID="btnSubmit" runat="server" Text="Submit" />


VB.Net Code for Registration.aspx page
  • In the code behind file (Registration.aspx.vb) write the code as:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Imports System.Net
Imports System.Net.Mail

Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("conStr").ConnectionString)

    Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click
        Dim msg As MailMessage
        Dim cmd As New SqlCommand()
        Dim ActivationUrl As String = String.Empty
        Dim emailId As String = String.Empty
        Try
            cmd = New SqlCommand("insert into Tb_Registration (Name,EmailId,Address,ContactNo) values (@Name,@EmailId,@Address,@ContactNo) ", con)
            cmd.Parameters.AddWithValue("@Name", txtName.Text.Trim())
            cmd.Parameters.AddWithValue("@EmailId", txtEmailId.Text.Trim())
            cmd.Parameters.AddWithValue("@Address", txtAddress.Text.Trim())
            cmd.Parameters.AddWithValue("@ContactNo", txtContactNo.Text.Trim())
            If con.State = ConnectionState.Closed Then
                con.Open()
            End If
            cmd.ExecuteNonQuery()

           Sending activation link in the email
            msg = New MailMessage()
            Dim smtp As New SmtpClient()
            emailId = txtEmailId.Text.Trim()
            'sender email address
            msg.From = New MailAddress("YourGmailEmailId@gmail.com")
            'Receiver email address
            msg.[To].Add(emailId)
            msg.Subject = "Confirmation email for account activation"
            'For testing replace the local host path with your lost host path and while making online replace with your website domain name
            ActivationUrl = Server.HtmlEncode("http://localhost:8665/MySampleApplication/ActivateAccount.aspx?UserID=" & FetchUserId(emailId) & "&EmailId=" & emailId)

            msg.Body = "Hi " & txtName.Text.Trim() & "!" & vbLf & "Thanks for showing interest and registring in <a href='http://www.webcodeexpert.com'> webcodeexpert.com<a> " & " Please <a href='" & ActivationUrl & "'>click here to activate</a>  your account and enjoy our services. " & vbLf & "Thanks!"
            msg.IsBodyHtml = True
            smtp.Credentials = New NetworkCredential("YourGmailEmailId@gmail.com", "YourGmailPassword")
            smtp.Port = 587
            smtp.Host = "smtp.gmail.com"
            smtp.EnableSsl = True
            smtp.Send(msg)
            clear_controls()
            ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "Message", "alert('Confirmation Link to activate account has been sent  to your email address');", True)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "Message", "alert('Error occured : " & ex.Message.ToString() & "');", True)
            Return
        Finally
            ActivationUrl = String.Empty
            emailId = String.Empty
            con.Close()
            cmd.Dispose()
        End Try
    End Sub

    Private Function FetchUserId(emailId As String) As String
        Dim cmd As New SqlCommand()
        cmd = New SqlCommand("SELECT UserId FROM Tb_Registration WHERE EmailId=@EmailId", con)
        cmd.Parameters.AddWithValue("@EmailId", emailId)
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If
        Dim UserID As String = Convert.ToString(cmd.ExecuteScalar())
        con.Close()
        cmd.Dispose()
        Return UserID
    End Function

    Private Sub clear_controls()
        txtName.Text = String.Empty
        txtEmailId.Text = String.Empty
        txtAddress.Text = String.Empty
        txtContactNo.Text = String.Empty
        txtName.Focus()
    End Sub

  • Add a new page “ActivateAccount.aspx”. This page will be opened when new registered user click on the activate account link in his email. On the page load it will check email id and user id from the query string and then update the "Is_Approved" column to 1 i.e. True. Then you can redirect him to your login page to log in.
In the code behind file (ActivateAccount.aspx.vb) and write the code on the page load event as:

Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ActivateMyAccount()
        End If
    End Sub

    Private Sub ActivateMyAccount()
        Dim con As New SqlConnection()
        Dim cmd As New SqlCommand()
        Try
            con = New SqlConnection(ConfigurationManager.ConnectionStrings("conStr").ConnectionString)

            If (Not String.IsNullOrEmpty(Request.QueryString("UserID"))) And (Not String.IsNullOrEmpty(Request.QueryString("EmailId"))) Then
                'approve account by setting Is_Approved to 1 i.e. True in the sql server table
                cmd = New SqlCommand("UPDATE Tb_Registration SET Is_Approved=1 WHERE UserID=@UserID AND EmailId=@EmailId", con)
                cmd.Parameters.AddWithValue("@UserID", Request.QueryString("UserID"))
                cmd.Parameters.AddWithValue("@EmailId", Request.QueryString("EmailId"))
                If con.State = ConnectionState.Closed Then
                    con.Open()
                End If
                cmd.ExecuteNonQuery()
                Response.Write("You account has been activated. You can <a href='Login.aspx'>Login</a> now! ")
            End If
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "Message", "alert('Error occured : " & ex.Message.ToString() & "');", True)
            Return
        Finally
            con.Close()
            cmd.Dispose()
        End Try
    End Sub

Now over to you:
"If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."
Previous
Next Post »

107 comments

Click here for comments
Anonymous
admin
September 05, 2013 ×

Fine Job but to send random password to user mail.

Reply
avatar
Anonymous
admin
September 06, 2013 ×

Great work :)Keep blogging!!

Reply
avatar
September 06, 2013 ×

thanks for the appreciation. stay tuned and stay connected for more useful updates..

Reply
avatar
Anonymous
admin
September 10, 2013 ×

hii sir, i have followed ol ur code, bt still my code nt works.. wat to do in this case????

Reply
avatar
September 10, 2013 ×

Please let me know the exact problem you are facing so that i can help you resolve that..

Reply
avatar
Danish Khan
admin
September 16, 2013 ×

sir why you are use Parameter variable without storedprocedure.
please sir tell me the role of it.

Reply
avatar
September 16, 2013 ×

Hello Danish..It is good programming practice and prevents from Sql injection and other hacking..So never pass the value to variable directly from the textbox,instead use this approach.

Reply
avatar
Danish Khan
admin
September 17, 2013 ×

thankyou sir
sir how i decide the name of parameter variable.is it the name of database table variable with @sign.

what is the use of cmd.ExecuteScalar() and Server.HtmlEncode

your code is very helpful to me .


Reply
avatar
September 17, 2013 ×

Hello Danish Khan, parameters name can be anything with the @ prefix..
ExecuteScalar executes the query and returns the very first column of first row, other columns and rows are ignored by this method.Basically it is used to retrieve single value from database.

The HTMLEncode method applies HTML encoding to a specified string.
I will try to create post related to the above so that you can better understand the concept.

Reply
avatar
Danish Khan
admin
September 18, 2013 ×

thank u sir

sir please create post. that discribed how to genrate pdf file in asp.net

Reply
avatar
Danish Khan
admin
September 18, 2013 ×

sorry sir i want ask you another query
related to this program. UserId is a primary key and it doesnt repeated in table .but emailId and contact number genrated ambigulty
we can easily inserted same emailId and contact no into another record.please tell me the solution

Reply
avatar
September 18, 2013 ×

Hi Danish..Read the below mentioned article to export gridview data to create pdf file http://www.webcodeexpert.com/2013/06/bind-and-export-gridview-data-to-pdf.html

Reply
avatar
Kumar Aryan
admin
September 20, 2013 ×

Dear Sir,
I want to convert a panel content into pdf file but i have not used table,tr and td anywhere inside panel content. i have used only div and css inside panel. when i am trying to convert in pdf its giving exception 'the page source is empty' like that type of message. is it possible to write div content in .pdf format using iTextSharp ?. Please help me..

When i am using table ,tr and td then its writing in pdf
but i am not able to provide a good look and feel in table,tr and td..
So ,please reply me how to write a div content.

Reply
avatar
Chirag Balar
admin
September 22, 2013 ×

when i click on button. it doesn't send the email and doesn't give any message. there is no any errors. can you upload the whole project of this email example??

Reply
avatar
September 22, 2013 ×

Hello chirag..Check your spam emails. sometime mails goes in the spam folder. Also have you changed the localhost path as per your application in the line
Server.HtmlEncode("http://localhost:8665/MySampleApplication/ActivateAccount.aspx?UserID=" + FetchUserId(emailId) + "&EmailId=" + emailId);

Please check and notify me..

Reply
avatar
Danish Khan
admin
September 23, 2013 ×

sir please give me the solution of my problum

Reply
avatar
September 23, 2013 ×

You can create emailid and contact number field the unique key..this way they can not be duplicated..

Reply
avatar
September 23, 2013 ×

Hello danish..You can create emailid and contact number field the unique key..this way they can not be duplicated..

Reply
avatar
Danish Khan
admin
September 24, 2013 ×

thank you sir.

sir please create a post about sharepoint.

Reply
avatar
September 24, 2013 ×

Hello Danish Khan..right now i am not covering sharepoint..but i will cover it in near future..keep reading..:)

Reply
avatar
Danish Khan
admin
September 25, 2013 ×

thankyou sir for response

Reply
avatar
September 25, 2013 ×

Your welcome danish..:)

Reply
avatar
Anonymous
admin
September 27, 2013 ×

hi sir,how send sms from asp.net website using way2sms

Reply
avatar
September 29, 2013 ×

hello..i will post an article to send sms from asp.net as soon as possible..so stay connected for more useful updates. :)

Reply
avatar
October 01, 2013 ×

sir activation page is not working please let know what is process?

Reply
avatar
October 01, 2013 ×

Hi Mithlesh..exactly what problem you are facing?

Reply
avatar
October 06, 2013 ×

Hii sir, i want to create pdf file and send it to the user. Give me guidelines for it.

Reply
avatar
Thilaga R
admin
October 07, 2013 ×

when i click on button. it doesn't send the email and doesn't give any message. there is no any errors. Pls help me

Reply
avatar
October 07, 2013 ×

Hello Thilaga R..Check your spam emails also. sometime mails goes in the spam folder. Also have you changed the localhost path as per your application in the line
Server.HtmlEncode("http://localhost:8665/MySampleApplication/ActivateAccount.aspx?UserID=" + FetchUserId(emailId) + "&EmailId=" + emailId);

Please check and notify me..

Reply
avatar
Thilaga R
admin
October 08, 2013 ×

i checked that...but no use..its urgent pls help me

Reply
avatar
October 09, 2013 ×

Have you tried debugging the code? if not then i suggest you to do that to know the exact problem in you code..check and notify me where you are getting error?

Reply
avatar
Thilaga R
admin
October 10, 2013 ×

there is no any errors sir. can you upload the whole project of this email?? because i m doing one project

Reply
avatar
October 10, 2013 ×

hello sir , how to get userid based on emailid and what is the FetchUserid ?
ActivationUrl = Server.HtmlEncode("http://localhost:8665/MySampleApplication/ActivateAccount.aspx?UserID=" + FetchUserId(emailId) + "&EmailId=" + emailId);

Reply
avatar
October 11, 2013 ×

hello sir , what is the FetchUserid and how to get userid from database?
the following query
ActivationUrl = Server.HtmlEncode("http://localhost:8665/MySampleApplication/ActivateAccount.aspx?UserID=" + FetchUserId(emailId) + "&EmailId=" + emailId);

Reply
avatar
October 14, 2013 ×

Hi, srikanth kalyan..FetchUserid is the function to get the userid based on entered email id. Userid is the primary key and will be unique always..

Reply
avatar
October 15, 2013 ×

thanks lalit sir,
i saw for ur activation link Blog.

Reply
avatar
October 15, 2013 ×

Your welcome roushan choudhary..stay connected and keep reading..:)

Reply
avatar
santu
admin
October 17, 2013 ×

how to generate random password that send to email id after registration is over...and that password is used for login..

Reply
avatar
santu
admin
October 17, 2013 ×

how to create auto generate passwords and send it newly created user email id....

Reply
avatar
santu
admin
October 17, 2013 ×

how to write code for auto generate password and send it to newly create user email id?

Reply
avatar
October 18, 2013 ×

Hello Santu..i will create an article as per your requirement and publish as soon as possible..so stay connected and keep reading for more updates..:)

Reply
avatar
Jeremy W
admin
October 30, 2013 ×

Great work thanks for this example!

Reply
avatar
October 30, 2013 ×

Hello Jeremy W..thanks for appreciating my work..keep reading and stay connected for more useful updates like this..:)

Reply
avatar
Raasitha A
admin
November 14, 2013 ×

Thanks for the wonderful tutorial.Graspable coding for beginners....

Reply
avatar
November 14, 2013 ×

It is always nice to hear that my tutorial helped anyone..Thanks Raasitha..:)

Reply
avatar
Anonymous
admin
November 20, 2013 ×

Very good sir

Reply
avatar
November 20, 2013 ×

thanks for the appreciation...:)

Reply
avatar
Anonymous
admin
November 26, 2013 ×

hello sir i want to create a inquiry form & when ever from fill by user then all information send in my email ///////////i am very confuse pls help me

Reply
avatar
November 27, 2013 ×

Hi, read the following article:
http://www.webcodeexpert.com/2013/08/create-contact-us-formpage-and-ajax.html

it will help you..

Reply
avatar
Anonymous
admin
November 28, 2013 ×

hello,
plz provide me solution for error ScriptManager does not exist in current context

Reply
avatar
November 29, 2013 ×

try to include System.Web.Extensions

Reply
avatar
December 08, 2013 ×

hi sir, i already applied everything u explained into this post but it doesn't work sending email point, please help me out doing this.

Reply
avatar
December 08, 2013 ×

Hello Mohammed Muthna..are you getting any error? if yes then send me the details of that error so that i can help you in solving that..:)

Reply
avatar
Aarti Bhopi
admin
December 26, 2013 ×

Hello sir,
My activation page is not working ??????
when i click on "click here to activate" this link. i redirect on ActivateAccount page
& i got this url (http://localhost/ActivateAccount.aspx?UserID=8&EmailId=jack@gmail.com)
but d whole page is blank.
please revert ASAP

Reply
avatar
December 26, 2013 ×

Hello Aarti..i suggest you to try to debug the code on page load of ActivateAccount.aspx page..this way you can get the exact error..then let me know the results..i will help you to solve your problem..

Reply
avatar
Aarti Bhopi
admin
December 27, 2013 ×

Thank's for u r reply.
i debug ActivateAccount.aspx page but still it is blank.
there is no any error.

signup.aspx page link is:

string link = Server.HtmlEncode("http://localhost/ActivateAccount.aspx?UserID=" + FetchUserId(emailId) + "&email=" + emailId);

is it correct???????


Reply
avatar
December 27, 2013 ×

Hello aarti..
there must be a 4 digit port number attached with your url e.g. http://localhost:8665 in the link..
when you will run the registration or signup.aspx page then check the url from browser, it will contain 4 digit port number also. add the port number in the url also..

it should look like ActivationUrl = Server.HtmlEncode("http://localhost:8665/MySampleApplication/ActivateAccount.aspx?UserID=" + FetchUserId(emailId) + "&EmailId=" + emailId);

Reply
avatar
Anonymous
admin
January 04, 2014 ×

Goodmoring from Greece
The article is great but when i run th app, i take this error
CS1502: The best overloaded method match for 'System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)' has some invalid arguments

Source Error:


Line 34: try
Line 35: {
Line 36: cmd=new SqlCommand("insert into Tb_Registration(Firstname,LastName,UserName,Password,EmailId,Phone,Address) values (@Firstname,@LastName,@UserName,@Password,@EmailId,@Phone,@Address)", con);
Line 37:
Line 38:

my email is kostasvit@gmail.com please help!!!!

Reply
avatar
January 06, 2014 ×

Hello..i suggest you to recheck your table fields and their data types and ensure that you are passing the values to these parameters properly..if still you face the problem then let me know..i will help you in sorting your problem..

Reply
avatar
Anonymous
admin
January 15, 2014 ×

Hellow Sir?I have deployed my application but dont want to hard code the url to send the email link to complete registration,how can i make sure it includes the current browser url i have than using my locallhost?

Reply
avatar
Mani Teja
admin
January 18, 2014 ×

Hi Sir Signup or Registration Page is Ok but
what about Login page and I trying this code for the login page without activating the link which come to my mail and now the login page is working without activating the link

Reply
avatar
aarzoo patel
admin
January 24, 2014 ×

Hello sir,
I tried to implement your code but somehow its not working.
It gives no error but when I click on the Submit button it redirect to the same page (Registration,aspx).
And the database is not updated also.
Please help me out.

Reply
avatar
January 24, 2014 ×

Hello aarzoo patel..i suggest you to recheck your code thoroughly and try once again..if still you face the problem then let me know..i will help you to sort out the issue..

Reply
avatar
aarzoo patel
admin
January 24, 2014 ×

The error was resolved.
Thank you sir for this valuable code.
And keep posting new stuffs it really helps a lot.

Reply
avatar
January 25, 2014 ×

Hi aarzoo patel..i am glad to know that you have resolved your issue..stay connected and keep reading..:)

Reply
avatar
Majeed Raju
admin
January 31, 2014 ×

Great Work and good effort to ans every Visitor ASAP Like it Really

Reply
avatar
February 01, 2014 ×

Thanks Majeed Raju for your appreciations..

Reply
avatar
rajat kumar
admin
February 04, 2014 ×

Hello sir
i went to put Google map of specific location in my site .
if you like to help me then pls help me.

Reply
avatar
February 04, 2014 ×

Hi rajat kumar..i will create an article as per your requirement and publish very soon..so stay connected and keep reading ...:)

Reply
avatar
Anonymous
admin
February 05, 2014 ×

So It don't need do anything in
protected void Page_Load(object sender, EventArgs e)
{

} for this registration page?

Reply
avatar
Anonymous
admin
February 05, 2014 ×

Hi Sir Could you make sure I don't need add any code in th Page_Load event class?

Reply
avatar
February 05, 2014 ×

Yes , you don't need to write any code in page load event..

Reply
avatar
February 05, 2014 ×

Yes , you don't need to write any code in page load event..

Reply
avatar
Anonymous
admin
February 05, 2014 ×

Thank you sir, I have a dropdown list in my table for user select different department. I code as:
cmd.Parameters.AddWithValue("@department",DropDownListDP.SelectedItem.ToString().Trim());

in the clear_Controls() code as: DropDownListDP.SelectedIndex = 0;
are they correct. Do I need add any in the ActiveAccount.aspx page.
I code as your way and run it , there are no any problem but no email, no data add to database, nothing happen. Could you tell me what's the problem. Thanks

Reply
avatar
Anonymous
admin
February 05, 2014 ×

Hi sir,If I want to create a registration compete page to show the successful message and error message. how can I do. If use entered same email address, how to validate and show message say: Your email address already be used.Thanks

Reply
avatar
Anonymous
admin
February 06, 2014 ×

Could you post your Reset Password code without using stored procedure database. I am doing a project don't want to use store procedure. This is an registration system. User register, receive email confirmation click the link in email to active account. Login, reset password if forget. Change password if received random given password. user can go their profile change their information. Logon.
Could help find code for all this steps without use stored procedure database. using very basic and easy way. thanks sir

Reply
avatar
Paulo
admin
February 07, 2014 ×

Hello Lalit,
I'd appreciate your advice and if possible help in the following:
Is it possible to activate the account by calling a Web Service? I mean, the user receives the e-mail with the activation link, and the activation/approval process is made by calling a Web Service, instead of a Web Page to make the process seamless for the user.
I'd be very thankful for your help/guidelines because it's huge demand made in a project I'm involved in.
Thank you very much in advance
Paul

Reply
avatar
February 08, 2014 ×

Hi, you can read the following article as per your requirement
http://www.webcodeexpert.com/2013/04/how-to-return-data-through-output.html

Reply
avatar
Anonymous
admin
February 20, 2014 ×

how to send data like name,address,contact information on email address in asp.net

Reply
avatar
nakul raju
admin
February 22, 2014 ×

hi, i have query regarding user registration whenever new user register have to generate user id and display in the label and using that id user have to login, so that next user should not have similar user id. also the previous registered user id should display automatically when next user login for new register.

thanks in advance

Reply
avatar
March 20, 2014 ×

i m a big fan of urs lalit.. god bless.
keep blogging..

Reply
avatar
March 23, 2014 ×

Hi Reshav..thanks for appreciating my work...it is always nice to hear that someone liked my work..:)

Reply
avatar
Anonymous
admin
April 25, 2014 ×

good one, but if I can download this.........

Reply
avatar
Anonymous
admin
April 25, 2014 ×

v

Reply
avatar
Anonymous
admin
April 25, 2014 ×

yes

Reply
avatar
Anonymous
admin
April 29, 2014 ×

Is it ok to use this code on my website

Reply
avatar
May 04, 2014 ×

Yes, of course you can with little or no modification as per your requirement..

Reply
avatar
riri
admin
May 05, 2014 ×

Hi, I want to registered an form in a database and have given an identifier for use later in my project, can you please help me

Reply
avatar
riri
admin
May 05, 2014 ×

Hi, I want to resgistred a form in a database and have given an identifier for use later in my project, can you please help me

Reply
avatar
July 17, 2014 ×

sir i want to upload doc file in wef form..but doc file id download ..i want this file no download drct show the page a read ..please help me

Reply
avatar
December 04, 2014 ×

How to get user details by entering his id in the registration form automatically by pressing enter button

Reply
avatar
Anonymous
admin
January 20, 2015 ×

Hello sir
good job
only one problem will u plz help me to solve?
port number get chnaged so cant redirected sometime wts d solution

ActivationUrl = Server.HtmlEncode("http://localhost:62788/redsun/ActivateAccount.aspx?UserId=" + FetchUserId(emailId) + "&EmailId=" + emailId);

Dis port is changed evry time

Reply
avatar
January 22, 2015 ×

When you make this page online you just need to replace the localhost path along with port number with your website name then it will work fine because the path will remain same always..

Reply
avatar
Bhavik Joshi
admin
February 10, 2015 ×

ScriptManager Does not Exist"
????

what is solution for this ?

Reply
avatar
February 10, 2015 ×

Hello Bhavik,
there may be two solutions to your problem. First include the namespace System.Web.UI
If still the problem remain the same then Go to solutions explorer -> right click on project -> Select add reference -> in .Net tab select System.Web.Extensions and click OK.
Please let me know it it resolved the issue or not?

Reply
avatar
Bhavik Joshi
admin
February 11, 2015 ×

in .net tab there is only System.web.Extensions .
so now waht's the problem ??

Reply
avatar
February 12, 2015 ×

Hi sir, is there any tutorial from you to create a complete website like way2sms? Needed for my project.
Thank you.

Reply
avatar
February 12, 2015 ×

Is System.web.Extensions checked? and have you included the namespace System.Web.UI ? I yes and still getting problem then send me the complete code , i will check and resolve your issue

Reply
avatar
February 12, 2015 ×

Hello Syed..Currently there is no such article as per your requirement. In future i will try to create that and post that here. so stay connected and keep reading..

Reply
avatar
February 28, 2015 ×

My coding is running successfully

Reply
avatar
An Qi
admin
August 06, 2015 ×

Hi, i got error at this line under private void activate account. can help me to solve the problem?

if (!string.IsNullOrEmpty(Request.QueryString["CUsername"]))&(!string.IsNullOrEmpty(Request.QueryString["CEmail"])))

Reply
avatar
August 07, 2015 ×

There must be && instead of single & in the code. Please correct that and it will work fine.

Reply
avatar
adla praveen
admin
October 29, 2015 ×

Thanx Lalit , it was really use full for me :)

Reply
avatar
adla praveen
admin
October 30, 2015 ×

Simple and very usefull. thank u sir |o|

Reply
avatar
November 01, 2015 ×

Ur welcome.Stay connected and keep reading for more useful updates like this..

Reply
avatar
November 01, 2015 ×

Ur welcome..I am glad you found this article helpful for you..:)

Reply
avatar
Najwa wawa
admin
November 17, 2015 ×

How to get notification email..because i already submit the registration form and check the db table, the IS APPROVED is 0 need to check the email?but i dont get any email. please help

#newbie

Reply
avatar

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily.. ConversionConversion EmoticonEmoticon