umair mohsin

umair mohsin

  • 1.3k
  • 387
  • 66.9k

ajax extension working held

Aug 26 2015 2:18 AM
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" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<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;
}
}

</script>
<style type="text/css">
.style12
{
width: 122px;
}
.style13
{
width: 40px;
}
.style14
{
width: 72px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<h3>welcome</h3>


<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" 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" 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()" />
<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" runat="server" 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>
</asp:Content>
 
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();
}
}
}
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
 
 

Answers (1)