TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Vikas
NA
831
195.1k
Newsletter Subscribe in Asp.Net
May 2 2018 5:07 AM
ASPX Code
<
div
class
=
"single"
>
<
div
class
=
"input-group"
>
<
asp:TextBox
ID
=
"txtsubemail"
runat
=
"server"
class
=
"form-control"
placeholder
=
"Enter your email address…"
ValidationGroup
=
"email"
>
</
asp:TextBox
>
<
span
class
=
"input-group-btn"
>
<!--<button class="btn btn-theme" type="submit">Subscribe</button> -->
<
asp:LinkButton
ID
=
"btnsubscribe"
runat
=
"server"
class
=
"btn btn-theme"
OnClick
=
"btnsubscribe_Click"
>
Subscribe
</
asp:LinkButton
>
</
span
>
<
asp:RequiredFieldValidator
ID
=
"require1"
runat
=
"server"
ForeColor
=
"red"
ControlToValidate
=
"txtsubemail"
ErrorMessage
=
"Please Enter Email"
ValidationGroup
=
"email"
Display
=
"Dynamic"
>
</
asp:RequiredFieldValidator
>
<
asp:RegularExpressionValidator
ID
=
"RegularExpressionValidator2"
runat
=
"server"
ErrorMessage
=
"Enter Valid Email ID"
ControlToValidate
=
"txtsubemail"
Display
=
"Dynamic"
CssClass
=
"requiredFieldValidateStyle"
ForeColor
=
"red"
EnabledEventValidation
=
"false"
ValidationExpression
=
"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup
=
"email"
>
</
asp:RegularExpressionValidator
>
</
div
>
</
div
>
.CS File
protected
void
btnsubscribe_Click(
object
sender, EventArgs e)
{
DataTable ddtab = con.GetdataTable(
"select * from tbl_newsletter where emailid='"
+ txtsubemail.Text.ToString().Trim() +
"'"
);
if
(ddtab.Rows.Count > 0)
{
Page.ClientScript.RegisterStartupScript(
typeof
(Page),
"msg"
,
"<script>alert('You have already subscribed')</script>"
);
txtsubemail.Text =
""
;
}
else
{
int
res = 0;
string
query =
"insert into tbl_newsletter (emailid,subscribe) values('"
+ txtsubemail.Text +
"','yes')"
;
res = con.ExecuteQuery(query);
if
(res > 0)
{
Page.ClientScript.RegisterStartupScript(
typeof
(Page),
"msg"
,
"<script>alert('You have subscribed successfully.')</script>"
);
txtsubemail.Text =
""
;
}
}
}
When I enter the email and submit the button then the output is not shown in the database so guys help me this problem.
Reply
Answers (
1
)
Entity framework code first migration issue
Binding two entities to dropdownlist in one view