my application has two buttons one validate user name and password having validation controls and other one is for addition purpose in which
i used ajax functionality using extensions here is my complete code
html
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Textbox Test.aspx.cs" Inherits="Default2" %>
welcome
ForeColor="Red"> | ||
ForeColor="Red"> | ||
calculating........
code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label7.Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
System.Threading.Thread.Sleep(3000);
double a, b, c;
a = Convert.ToDouble(TextBox1.Text);
b = Convert.ToDouble(TextBox2.Text);
c = a + b;
Label7.Text = c.ToString();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label7.Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
System.Threading.Thread.Sleep(3000);
double a, b, c;
a = Convert.ToDouble(TextBox1.Text);
b = Convert.ToDouble(TextBox2.Text);
c = a + b;
Label7.Text = c.ToString();
}
}
}
avoid scriptmanager proxy and content controls but whenever click on addition button validation controls stops the process as above textboxes are empty.if i want to perform additions and leave above textboxes blank then how could i do that.
i also uploaded a word file for more clear code
Upendra Pratap ShahiPosted Aug 26, 2015, 5:15 AM
Design page
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="AjaxTest.aspx.cs" Inherits="AjaxTest" %>
DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>title>
<script type="text/javascript" language="javascript">
function validate() {
var name = document.getElementById('<%=txtname.ClientID %>');
var psw = document.getElementById('<%=txtpassword.ClientID %>');
if (name.value == "")
{
name.style.border = "2px solid red";
if (psw.value == "")
{
psw.style.border = "2px solid red";
}
return false;
}
}
function NumberValidate() {
var firstnum = document.getElementById('<%=TextBox1.ClientID %>');
var secondnum = document.getElementById('<%=TextBox2.ClientID %>');
if (firstnum.value == "" || secondnum.value == "") {
firstnum.style.border = "2px solid red";
secondnum.style.border = "2px solid red";
alert("must enter the value!");
return false;
}
else
return true;
}
script>
<style type="text/css">
.style12 {
width: 122px;
}
.style13 {
width: 40px;
}
.style14 {
width: 72px;
}
style>
head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="scm" runat="server">asp:ScriptManager>
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
asp:ScriptManagerProxy>
<h3>welcomeh3>
<table class="style1">
<tr>
<td class="style13">
<asp:Label ID="Label2" runat="server" Text="Name:">asp:Label>
td>
<td class="style12">
<asp:TextBox ID="txtname" runat="server">asp:TextBox>
td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtname" ValidationGroup="test" Display="Dynamic" ErrorMessage="Required Field"
ForeColor="Red">asp:RequiredFieldValidator>
td>
tr>
<tr>
<td class="style13">
<asp:Label ID="Label4" runat="server" Text="Password:">asp:Label>
td>
<td class="style12">
<asp:TextBox ID="txtpassword" runat="server" TextMode="Password">asp:TextBox>
td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtpassword" ValidationGroup="test" Display="Dynamic" ErrorMessage="Required Field"
ForeColor="Red">asp:RequiredFieldValidator>
td>
tr>
<tr>
<td class="style13" colspan="3">
<asp:Label ID="Label3" runat="server" Text="Label">asp:Label>
td>
tr>
<tr>
<td class="style13" colspan="3">
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="validate()" ValidationGroup="test" />
<br />
td>
tr>
table>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table class="style1">
<tr>
<td class="style14">
<asp:Label ID="Label5" runat="server" Text="1st value:">asp:Label>
td>
<td>
<asp:TextBox ID="TextBox1" runat="server">asp:TextBox>
<asp:Button ID="Button2" ClientIDMode="Static" runat="server" OnClientClick="NumberValidate()" OnClick="Button2_Click"
Text="Addition" />
td>
tr>
<tr>
<td class="style14">
<asp:Label ID="Label6" runat="server" Text="2nd value:">asp:Label>
td>
<td>
<asp:TextBox ID="TextBox2" runat="server">asp:TextBox>
<asp:Label ID="Label7" runat="server" Text="Label">asp:Label>
td>
tr>
table>
ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button2" />
Triggers>
asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<p><i>calculating........i>p>
ProgressTemplate>
asp:UpdateProgress>
div>
form>
body>
html>
Codebehind Page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Text;
public partial class AjaxTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label7.Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
System.Threading.Thread.Sleep(3000);
double a, b, c;
if (TextBox1.Text != "" && TextBox2.Text != "")
{
a = Convert.ToDouble(TextBox1.Text);
b = Convert.ToDouble(TextBox2.Text);
c = a + b;
Label7.Text = c.ToString();
}
}
}
}
In webconfig
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
appSettings>