How to pass variable value to a class asp.net
i have a page where user request to get password
my code as follow
HTML
<form method="post" class ="register-form" action="#">
<div class="input-group">
<input type="text" name="user_login" id="username" class="form-control" placeholder="Registered Email Address">
</div>
<br>
<asp:button id="btnreset" runat="server" text="Get password" onclick="btnreset_Click" cssclass="btn btn-primary btn-lg btn-block" /><br />
<asp:label id="lblmsg" runat="server" text=""></asp:label>
</form>
code behind
public pass as string
Protected Sub btnreset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnreset.Click
Dim id As String = Request.Form("user_login").ToString
Dim constring As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Using con As New SqlConnection(constring)
Try
Dim ss As String = "select Password from users where Email_ID='" & id & "'"
con.Open()
Dim comm As New SqlCommand(ss, con)
Dim dr As SqlDataReader = comm.ExecuteReader
If dr.Read Then
pass = dr.Item(0)
sendmail()
lblmsg.Text = "You password has been sent."
End If
'lblmsg.Text = fn.ToString & ln.ToString
Catch ex As Exception
lblmsg.Text = ex.Message.ToString
Finally
con.Close()
End Try
End Using
End Sub
Protected Sub sendmail()
Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
sb.Append("Password Request")
sb.AppendLine()
sb.Append("E-mail Id - " + Request.Form("user_login").ToString)
sb.AppendLine()
sb.Append("your password is - " + pass)
Dim m As Mail = New Mail()
Dim ackmsg As String = String.Empty
Dim status As Boolean = m.sendmail(sb.ToString(), "Password Request")
If (status) Then
ackmsg = "Your PAssword has sent successfully"
Else
ackmsg = "Sorry! An error has encountered. Please try again"
End If
End Sub
my class
using System;
using System.Collections.Generic;
using System.Web;
using System.Net.Mail;
/// <summary>
/// Summary description for Mail
/// </summary>
public class Mail
{
public Mail()
{
//
// TODO: Add constructor logic here
//
}
public bool sendmail(string msgbody, string msgsub)
{
bool status=false;
SmtpClient client = new SmtpClient("mysmtp.in", 25); //host and port picked from web.config
client.EnableSsl = false;
MailAddress from = new MailAddress("info@mysmtp.in", "Site Admin");
MailAddress to = new MailAddress("yogesh.0650@gmail.com", "User");
MailMessage message = new MailMessage(from, to);
message.Body = msgbody;
message.Subject = msgsub;
client.Credentials = new System.Net.NetworkCredential("info@mysmtp.in", "MYpassword");
try
{
client.Send(message);
status = true;
return status;
}
catch (Exception ex)
{
//Console.WriteLine("Exception is:" + ex.ToString());
status = false; //or return the error by some other means, say on a label
return status;
}
}
public bool sendmail(string msgbody, string msgsub, string emailto)
{
bool status = false;
SmtpClient client = new SmtpClient("mysmtp.in", 25); //host and port picked from web.config
client.EnableSsl = false;
MailAddress from = new MailAddress("info@mysmtp.in", "Site Admin");
MailAddress to = new MailAddress(emailto, "User");
MailMessage message = new MailMessage(from, to);
message.Body = msgbody;
message.Subject = msgsub;
client.Credentials = new System.Net.NetworkCredential("info@mysmtp.in", "MYpassword");
try
{
client.Send(message);
status = true;
return status;
}
catch (Exception ex)
{
//Console.WriteLine("Exception is:" + ex.ToString());
status = false; //or return the error by some other means, say on a label
return status;
}
}
}
i want use the second function in class and hoe to pass variable value from aspx.vb to class emailto
please help