How stop enter in function sendEmail() if textBox not filled, only if TextBox there is something go in sendEmail()
ps. How copy text from your forum, is not allow?
Source:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %>
<!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 id="Head1" runat="server">
<title></title>
<style type="text/css">
.modal
{
position: fixed;
top: 0;
left: 0;
background-color: black;
z-index: 99;
opacity: 0.8;
filter: alpha(opacity=80);
-moz-opacity: 0.8;
min-height: 100%;
width: 100%;
}
.loading
{
font-family: Arial;
font-size: 10pt;
border: 5px solid #67CFF5;
width: 200px;
height: 100px;
display: none;
position: fixed;
background-color: White;
z-index: 999;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function ShowProgress() {
setTimeout(function () {
var modal = $('<div />');
modal.addClass("modal");
$('body').append(modal);
var loading = $(".loading");
loading.show();
var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
loading.css({ top: top, left: left });
}, 200);
}
$('form').live("submit", function () {
ShowProgress();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtSubject" runat="server" Text="" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvSubject" runat="server" ErrorMessage="Enter subject" ControlToValidate="txtSubject"></asp:RequiredFieldValidator>
<br/>
<asp:TextBox ID="txtBody" runat="server" Text="" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvBody" runat="server" ErrorMessage="Enter body" ControlToValidate="txtBody"></asp:RequiredFieldValidator>
<br/>
<asp:Button ID="btnSend" runat="server" Text="SEND" OnClick="btnSend_Click" />
<div class="loading" align="center">
Loading. Please wait.<br />
<br />
<img src="loader.gif" alt="" />
</div>
</form>
<script type="text/javascript">
function WebForm_OnSubmit() {
if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit == false) {
for (var i in Page_Validators) {
try { }
catch (e) { }
}
return false;
}
ShowProgress();
return true;
}
</script>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class CS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//string script = "$(document).ready(function () { $('[id*=btnSubmit]').click(); });";
//ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);
}
}
protected void btnSend_Click(object sender, EventArgs e)
{
// Add Fake Delay to simulate long running process.
System.Threading.Thread.Sleep(5000);
SendEmail();
}
private void SendEmail()
{
string test = "TEST!";
string test2 = "TEST!";
}
}