Category ASP.NET

Show Alert Box From Serverside in Asp.net

Category: ASP.NETC#.Net Comments: No comments

Show Alert Box From Serverside in Asp.net

//Fuction for Alert Box

protected void jsCall(string alertmessage)
{

string script = @”alert( “”" + alertmessage+ @”"” );”;
ScriptManager.RegisterStartupScript(this, this.GetType(), “jsCall”, script, true);
}
//Call “jsCall” Function with message where u want.

jsCall(“Alert successfully.”);

Read More

Use of UrlEncode and UrlDecode Method in Asp.net

Category: ASP.NETC#.Net Comments: No comments

Use of UrlEncode and UrlDecode Method in Asp.net

UrlEncode Method :

HttpUtility.UrlEncode(string)
Ex:
string encodedText= HttpUtility.UrlEncode(txtrefcode.Text.Trim())
string url = “Test.aspx?enc=” + encodedText;
Response.Redirect(url);

UrlDecode Method :

HttpUtility.UrlDecode(Encoded String);
Ex:
string decodeValue = HttpUtility.UrlDecode(Request.QueryString["enc"]);

Read More

Send Mail in Forget Password Using Config File in Asp.net

Category: ASP.NETMAIL WORKSWEB CONFIG Comments: One comment

Creating SMTP in Web Config File

<configuration>
<connectionStrings>
<add name=”Connection” connectionString=”Data Source=.\SQLExpress;Initial Catalog=practise;Integrated Security=True;” providerName=”System.Data.SqlClient”/>
</connectionStrings>
<system.net>
<mailSettings >
<smtp>
<network host=”smtp.gmail.com” port=”587″ userName=”Email Id” password=”Password” />
</smtp>
</mailSettings>
</system.net>
<appSettings>
<add key=”MailFrom” value=”Email Id”/>
</appSettings>
</configuration>
//Call this Function From where u want to sen Email using App Settings in Config File

public bool ForgetEmail(string UserName)
{
string Connection = ConfigurationManager.ConnectionStrings["Connection"].ToString();
SqlConnection con = new SqlConnection(Connection);
con.Open();

SqlCommand command = new SqlCommand(“SELECT Password from UserTable where email=’” + UserName + “‘ “, con);
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables["Table"].Rows.Count > 0)
{

SmtpClient sm = new SmtpClient();
MailMessage msg = new MailMessage();

string msgfromadd = ConfigurationManager.AppSettings["MailFrom"];
MailAddress frmadd = new MailAddress(msgfromadd);
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.From = frmadd;
msg.To.Add(EmailID);
msg.Subject = “Your Password.”;
msg.Body = “Your password is:”+” “+ds.Tables["Table"].Rows[0][0].ToString();
msg.IsBodyHtml = true;
con.Close();
sm.EnableSsl = true;

sm.Send(msg);
return true;
con.Close();
}
else
{
return false;
con.Close();
}
}

Read More

Send Mail Using Config File in Asp.net

Category: ASP.NETMAIL WORKSWEB CONFIG Comments: No comments

Creating SMTP in Web Config File

<configuration>
<system.net>
<mailSettings >
<smtp>
<network host=”smtp.gmail.com” port=”587″ userName=”Email Id” password=”Password” />
</smtp>
</mailSettings>
</system.net>
<appSettings>
<add key=”MailFrom” value=”Email Id”/>
</appSettings>
</configuration>
//Call this Function From where u want to sen Email using App Settings in Config File

public bool SendEmail(string name, string email, string sub,string msg1,string phone )
{
SmtpClient sm = new SmtpClient();
MailMessage msg = new MailMessage();

string msgfromadd = ConfigurationManager.AppSettings["MailFrom"];
MailAddress frmadd = new MailAddress(msgfromadd);
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.From = frmadd;
msg.To.Add(email);
msg.Subject = name + ” ” + sub + ” ” + phone;
msg.Body = msg1;
msg.IsBodyHtml = true;

sm.EnableSsl = true;
try
{
sm.Send(msg);
return true;
}
catch
{
return false;
}
}

Read More

Asp.net Pass Multiple Parameters in Query String or URL

Category: ASP.NET Comments: No comments

If we want to send multiple parameters from one page to another page we need to write code like this

protected void btnSend_Click(object sender, EventArgs e)
{
Response.Redirect(“Default2.aspx?UserId=”+txtUserId.Text+”&UserName=”+txtUserName.Text);
}

 

Now we need to get these values in another page (here I mentioned Default2.aspx) by using QueryStringParameter values with variable names or index values that would be like this
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
lblUserId.Text = Request.QueryString["UserId"];
lblUserName.Text = Request.QueryString["UserName"];
}
}
Or
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
lblUserId.Text = Request.QueryString[0];
lblUserName.Text = Request.QueryString[1];
}
}

 

Read More

Save/Upload files in folder and download files from folder in asp.net

Category: ASP.NET Comments: No comments

To implement this first design table in your database like below to save file details in database. Column Name Data Type Allow Nulls Id int(set identity property=true) No FileName varchar(50) Yes FilePath varchar(50) Yes Now create new website after that right click on your website and add new folder and give name as Filesbecause here I am using same name for my sample if you want to change folder name you need to change the Files folder name in your code behind also After that design your aspx page like this Read More

3-Tier Architecture in asp.net using C# with Crude Operations

Category: ASP.NETC#.NetTHREE TIER ARCHITECTURE Comments: 7 comments

3-Tier Architecture in asp.net using c# 3-Tier architecture consists of 1) UI or Presentation Layer 2) Business Access Layer or Business Logic Layer 3) Data Access Layer Presentation Layer Presentation layer consists of pages like .aspx or desktop based form where data is presented to users or getting input from users. Business Logic layer or Business Access Layer Business logic layer contains all of the business logic. Its responsibility is to validate the business rules of the component and communicating with the Data Access Layer. Business Logic Layer is the class in which we write functions that get data from Presentation Layer and send that data to database through Data Access Layer.Read More

Handling JSON returned from ASP.NET Web Services with JQuery

Category: ASP.NETJQUERYWEB SERVICE Comments: No comments

There appear to be many articles showing how to use jQuery with ASP.NET Web Services around, but the vast majority of them illustrate the use of PageMethods that return a single value - typically "Hello World!" or the current date and time. Not much use in the real world, where you may more often need to call a service that returns a collection of complex objects. Here are a couple of examples that look at playing with more than just simple values. Follow Two Steps for Implementation Step 1: Add below section to Head Tag Read More

Show Alternate Color of Header in Data List Control

Category: ASP.NETJQUERY Comments: No comments

Follow two steps for implementation Step 1: Add below section to Head Tag Read More

Custom TextEditor with the Help Jquery in Asp.net

Category: ASP.NETJQUERY Comments: No comments

Follow two steps for implementation Step 1: Add below section to Head Tag Read More