This article will show you how you can create a news letter subscription for your website
using css, asp.net in your asp.net application.
Some of my previous articles are as follows: Stylish
Button Using Css3 In Asp.net, How
to Get Mouse Pointer Cordinate Inside a Div Using jQuery In Asp.Net,
Get
User Detail Like City,County,Region,Zip Code Using IP Address In Asp.Net,
Facebook
Style Lightbox jQuery Plugin To Display Images Like Facebook In Asp.Net,
Webcam
Integration Using jQuery Webcam Plugin In Asp.Net, Asp.Net
Dynamic jQuery Photo Gallery Plugin With Zoom Effect Using Css, Magnifying
Glass Effect Of Image Using jQuery in MVC.
So for this article firsat we will create a new asp.net
application and add the below code in your asp.net application.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="NewsLetter.WebForm1"
%>
<!DOCTYPE html
PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sign Up
Form For Newsletter In Asp.Net Using C# and Css3</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="header">
<p>
Sign Up For Newsletter</p>
</div>
<div class="description">
<p>
Sign Up Form For Newsletter In
Asp.Net Using C# and Css3
</p>
</div>
<div class="input">
<input class="button" id="email" name="email" placeholder="name@example.com" runat="server"
/>
<asp:Button ID="submit" runat="server" Text="SIGN UP" CssClass="button"
onclick="submit_Click" />
</div>
</form>
</body>
</html>
|
In above code I have added the css style sheet to display the stylish form to add email id.
<link href="css/style.css" rel="stylesheet" type="text/css" />
|
Now check he below code to save the data in DB.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace NewsLetter
{
public partial class WebForm1 : System.Web.UI.Page
{
protected
void Page_Load(object
sender, EventArgs e)
{
}
protected
void submit_Click(object
sender, EventArgs e)
{
try
{
SqlConnection
con = new SqlConnection("<---Your connection string ---->");
string
query = "Insert into Sucscription(EmailId) values('" + email.Value + "');";
SqlDataAdapter
da = new SqlDataAdapter(query,
con);
da.SelectCommand.ExecuteNonQuery();
lblMessage.Text = "Subscription sone successfully.";
}
catch
(Exception ex)
{
lblMessage.Text =
ex.Message.ToString();
}
}
}
}
|
In above query Sucscription is a table in which we will save the data. Now we have done. Run the application to check the output.
Please, please parameterize your inserts. Implementing as shown above will make you susceptible to SQL injection.
ReplyDelete