.net Ajax asyncronus postback probs

M

Mukesh

HI
all

I have created a user ctrl for user info.
On which i have used some asp ctrls, .net Ajax (Atlas) Ctrls and
validation as described below

Name TxtBox1(RequiedFieldValidator, RagexValidetor)
Email TxtBox2(RequiedFieldValidator, RagexValidetor)
Mobile Txtbox3(RagexValidetor)
Date of Birth txtBox4+CalenderExtender(Ajax Ctrl tool kit)(RagexValidetor)
Country DropDownMenu1 (autoppostback)
State DropDownMenu2 (autoppostback)
City DropDownMenu3 (autoppostback)
Address TextBox5
Pincode TextBox6

When i select country the state list is populated and slecting sate the
city list is populated and city selection prefills the pincode.
The whole User Ctrl is places in User.aspx in a UpdatePanel. so all the
post backs are asyncronus callbacks.


Problem is that when i selects the country all the Validation goes
inactive using firefox. an in ie it given null exception alert please help
me


Thx in advance

:
MUKESH AGARWAL
DELHI
 
W

Walter Wang [MSFT]

Hi Mukesh,

Would you please post a complete code listing of your control so that I can
reproduce the issue on my side? Thanks.

By the way, please note CalendarExtender is part of AJAX Control Toolkit
that is shared source supported by community.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi Mukesh,

Is the issue solved now?

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

// The .ascx file


<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="EditProfile.ascx.cs" Inherits="UserControls_EditProfile" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
First Name
</td>
said:
</asp:TextBox></td>
</tr>
<tr>
<td>
Middle Name
</td>
said:
</asp:TextBox></td>
</tr>
<tr>
<td>
Last Name
</td>
said:
</asp:TextBox></td>
</tr>
<tr>
<td>
Email</td>
said:
</asp:TextBox></td>
</tr>
<tr>
<td>
Date Of Birth</td>
said:
</asp:TextBox>
<div style="font-size: 90%">
<em>(Set the focus to the textbox to show the calendar)</em></div>
<ajaxToolkit:CalendarExtender
ID="CalendarExtender1" runat="server" Format="MMMM d, yyyy"
TargetControlID="tbDate" FirstDayOfWeek="Sunday">
</ajaxToolkit:CalendarExtender>
</td>
</tr>
<tr>
<td>
Gender
</td>
<td>
<asp:RadioButtonList ID="rblGen" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem Selected="True" Value="1">Male</asp:ListItem>
<asp:ListItem Value="0">Female</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td>
Telephone
</td>
said:
</asp:TextBox><asp:RegularExpressionValidator
ID="revTelIsd" runat="server" ControlToValidate="tbTelIsd"
ErrorMessage="Enter the Proper ISD Code"
SetFocusOnError="True" ValidationExpression="([0-9]+)$"
*</asp:RegularExpressionValidator>
<asp:TextBox ID="tbTelStd" runat="server" MaxLength="7"
</asp:TextBox><asp:RegularExpressionValidator
ID="revTelStd" runat="server" ControlToValidate="tbTelStd"
ErrorMessage="Enter the Proper STD Code,max Length is 4"
SetFocusOnError="True" ValidationExpression="([0-9]+)$"
*</asp:RegularExpressionValidator><asp:TextBox ID="tbTelLcl" runat="server"
MaxLength="20" ></asp:TextBox><asp:RegularExpressionValidator
ID="revTelLcl" runat="server" ControlToValidate="tbTelLcl"
ErrorMessage="Only integers value allowed"
SetFocusOnError="True" ValidationExpression="([0-9]+)$"
*</asp:RegularExpressionValidator></td>
</tr>
<tr style="color: #000000">
<td>
Mobile
</td>
said:
</asp:TextBox><asp:RegularExpressionValidator
ID="revMobIsd" runat="server" ControlToValidate="tbMobIsd"
ErrorMessage="Enter the Proper ISD Code"
SetFocusOnError="True" ValidationExpression="([0-9]+)$"
*</asp:RegularExpressionValidator>
<asp:TextBox ID="tbMobLcl" runat="server" MaxLength="20"
</asp:TextBox><asp:RegularExpressionValidator
ID="revMobLcl" runat="server" ControlToValidate="tbMobLcl"
ErrorMessage="Only integers value allowed"
SetFocusOnError="True" ValidationExpression="([0-9]+)$"
*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td colspan="2">
Address
</td>
</tr>
<tr>
<td>
Country</td>
<td>

<ContentTemplate>
<asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="True"
DataSourceID="XmlDataSource1"
DataTextField="name" DataValueField="countryCode"
OnDataBound="ddlCountry_DataBound"
OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="0">--- Select Country
---</asp:ListItem>
</asp:DropDownList><asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/App_Data/CountriesStates.xml"
XPath="root/Countries/country"></asp:XmlDataSource>
</ContentTemplate>

</td>
</tr>
<tr>
<td>
State</td>
<td>

<ContentTemplate>
<asp:DropDownList ID="ddlStt" runat="server" AutoPostBack="True"
DataSourceID="XmlDataSource2"
DataTextField="Name" DataValueField="id"
OnSelectedIndexChanged="ddlStt_SelectedIndexChanged"
OnDataBound="ddlStt_DataBound">
<asp:ListItem Selected="True" Value="0">--- Select State
---</asp:ListItem>
</asp:DropDownList><asp:TextBox ID="tbState" runat="server" MaxLength="50"
Visible="False"></asp:TextBox><asp:XmlDataSource
ID="XmlDataSource2" runat="server"
DataFile="~/App_Data/CountriesStates.xml"
XPath="root/states/state"></asp:XmlDataSource>
</ContentTemplate>

<asp:RegularExpressionValidator
ID="revSta" runat="server" ControlToValidate="tbState"
ErrorMessage="RegularExpressionValidator"
SetFocusOnError="True"
ValidationExpression="^(\w*\W*\w*\W*)*[^0-9][^ said:
*</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td>
City</td>
<td>

<ContentTemplate>
<asp:DropDownList ID="ddlCti" runat="server"
OnSelectedIndexChanged="ddlCti_SelectedIndexChanged" AutoPostBack="True">
</asp:DropDownList>
<asp:TextBox ID="tbCity" runat="server" MaxLength="50"
Visible="False">My City</asp:TextBox>
</ContentTemplate>

<asp:RegularExpressionValidator
ID="revCty" runat="server" ControlToValidate="tbCity"
ErrorMessage="RegularExpressionValidator"
SetFocusOnError="True"
ValidationExpression="^(\w*\W*\w*\W*)*[^0-9][^ said:
*</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td>
Locality</td>
<td>

<ContentTemplate>
<asp:DropDownList ID="ddlLocal" runat="server"
OnSelectedIndexChanged="ddlLocal_SelectedIndexChanged" AutoPostBack="True">
</asp:DropDownList>
<asp:TextBox ID="tbLcl" runat="server" MaxLength="50" Visible="False">My
Locality Name</asp:TextBox>
</ContentTemplate>

<asp:RegularExpressionValidator
ID="revLcl" runat="server" ControlToValidate="tbLcl"
ErrorMessage="RegularExpressionValidator"
SetFocusOnError="True" ValidationExpression='^(\w*\W*\w*\W*)*[^ said:
*</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td>
Street1</td>
said:
</asp:TextBox></td>
</tr>
<tr>
<td>
Street2</td>
said:
</asp:TextBox></td>
</tr>
<tr>
<td style="height: 26px">
Pincode</td>
<td>

<ContentTemplate>
<asp:TextBox ID="tbPin1" runat="server" MaxLength="15"
Visible="False"></asp:TextBox><asp:TextBox ID="tbPin" runat="server"
MaxLength="6" ></asp:TextBox>
</ContentTemplate>

<asp:RegularExpressionValidator
ID="revPin" runat="server" ControlToValidate="tbPin" ErrorMessage="Only
6 digit is allowed"
SetFocusOnError="True" ValidationExpression="\d{6}"
*</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:ValidationSummary ID="vsUsrPerIn" runat="server" >
</asp:ValidationSummary>
<asp:Label ID="lblMessage" runat="server"
EnableViewState="False"></asp:Label></td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click"
Text="Submit" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>




//----------------- the ascx.cs file-------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserControls_EditProfile : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
/// chk for sseion
/// call prefill
Propertywala.User user =
(Propertywala.User)Session[Propertywala.Constants.CommonConsts.USER_SESSION_NAME];
bool chkNull = Convert.IsDBNull(user.HomeAddress.Country);
if (!Convert.IsDBNull(user.HomeAddress.Country))
{
tbFirstName.Text = user.FirstName;
tbMiddleName.Text = user.MiddleName;
tbLastName.Text = user.LastName;
tbEmail.Text = user.PrimaryEmail;
DateTime dob = new DateTime();
DateTime.TryParse(user.DateOfBirth, out dob);
string dobst = dob.ToLongDateString();
tbDate.Text = dobst.Remove(0, dobst.IndexOf(",") + 1);
rblGen.SelectedIndex = 1;
if (user.IsUserMale)
{
rblGen.SelectedIndex = -1;
rblGen.SelectedIndex = 0;
}

tbTelIsd.Text = user.TelephoneIsd;
tbTelLcl.Text = user.TelephoneLocal;
tbTelStd.Text = user.TelephoneStd;
tbMobIsd.Text = user.MobileIsd;
tbMobLcl.Text = user.MobileLocal;
tbStr1.Text = user.AddressStreet1;
tbStr2.Text = user.AddressStreet2;
if (user.HomeAddress.Pin != "")
{
tbPin.Text = user.HomeAddress.Pin;
tbPin1.Text = user.HomeAddress.Pin;
}
tbCity.Text = user.HomeAddress.City;
tbLcl.Text = user.HomeAddress.Locality;
tbState.Text = user.HomeAddress.State;
}
}
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
Page.Validate("EditProfile");
if (Page.IsValid)
{
Propertywala.User user =
(Propertywala.User)Session[Propertywala.Constants.CommonConsts.USER_SESSION_NAME];
user.MiddleName = tbMiddleName.Text;
user.DateOfBirth = tbDate.Text;
user.IsUserMale = false;
if (rblGen.SelectedValue == "1")
{
user.IsUserMale = true;
}
user.TelephoneIsd = tbTelIsd.Text;
user.TelephoneLocal = tbTelLcl.Text;
user.TelephoneStd = tbTelStd.Text;
user.MobileIsd = tbMobIsd.Text;
user.MobileLocal = tbMobLcl.Text;

user.AddressStreet1 = tbStr1.Text;
user.AddressStreet2 = tbStr2.Text;
user.HomeAddress = new Propertywala.Address();
user.HomeAddress.Country = ddlCountry.SelectedValue;
if (string.Compare(user.HomeAddress.Country, "In", true) == 0)
{
user.HomeAddress.StateId = long.Parse(ddlStt.SelectedValue);
if (ddlCti.SelectedValue.Length > 0)
{
user.HomeAddress.CityId = long.Parse(ddlCti.SelectedValue);
}
if (ddlLocal.SelectedValue.Length > 0)
{
user.HomeAddress.LocalityId = long.Parse(ddlLocal.SelectedValue);
}
user.HomeAddress.City = tbCity.Text;
user.HomeAddress.Locality = tbLcl.Text;
user.HomeAddress.Pin = tbPin.Text;

}
else
{
user.HomeAddress.State = tbState.Text;
user.HomeAddress.City = tbCity.Text;
user.HomeAddress.Locality = tbLcl.Text;
user.HomeAddress.Pin = tbPin1.Text;
}

user.updateUserData();
lblMessage.Text = Propertywala.Common.CreateWarning("Profile Updated");
Response.Redirect("../User/Profile.aspx?view=ext");
}
}
protected void ddlCountry_DataBound(object sender, EventArgs e)
{
Propertywala.User user =
(Propertywala.User)Session[Propertywala.Constants.CommonConsts.USER_SESSION_NAME];
bool chkNull = Convert.IsDBNull(user.HomeAddress.Country);
if (!chkNull)
{
ddlCountry.Items.FindByValue(user.HomeAddress.Country).Selected = true;
}
VisibleInputFields();
}

protected void ddlStt_DataBound(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bool isIndian = false;
if (ddlCountry.SelectedItem.Text == "India")
{
isIndian = true;
}
Propertywala.User user =
(Propertywala.User)Session[Propertywala.Constants.CommonConsts.USER_SESSION_NAME];
bool chkNull = Convert.IsDBNull(user.HomeAddress.State);
if (!chkNull && isIndian)
{
ddlStt.SelectedIndex = -1;
ListItem state = ddlStt.Items.FindByText(user.HomeAddress.State);
if (state != null)
{
state.Selected = true;
}
else
{
tbState.Text = user.HomeAddress.State;
tbState.Visible = true;
}
}
ListItemCollection licLocal =
Propertywala.Address.GetLocalCollection(long.Parse(ddlStt.SelectedValue),
true, "City");
foreach (ListItem li in licLocal)
{
ddlCti.Items.Add(li);
}
chkNull = Convert.IsDBNull(user.HomeAddress.City);
if (!chkNull && isIndian)
{
ddlCti.SelectedIndex = -1;
ListItem city = ddlCti.Items.FindByText(user.HomeAddress.City);
if (city != null)
{
city.Selected = true;
ddlCti.DataBind();
licLocal =
Propertywala.Address.GetLocalCollection(long.Parse(ddlCti.SelectedValue),
true, "Locality");
foreach (ListItem li in licLocal)
{
ddlLocal.Items.Add(li);
}
chkNull = Convert.IsDBNull(user.HomeAddress.Locality);
if (!chkNull && isIndian)
{
ddlLocal.Visible = true;
ddlLocal.SelectedIndex = -1;
ListItem local =
ddlLocal.Items.FindByValue(user.HomeAddress.LocalityId.ToString());
if (local != null)
{
local.Selected = true;
ddlLocal.DataBind();
}
else
{
tbLcl.Text = user.HomeAddress.Locality;
tbLcl.Visible = true;
ddlLocal.SelectedIndex=ddlLocal.Items.Count-1;

}
}
}
else
{
tbCity.Text = user.HomeAddress.City;
tbCity.Visible = true;
tbLcl.Text = user.HomeAddress.Locality;
tbLcl.Visible = true;
ddlLocal.Visible = false;
ddlCti.SelectedIndex = ddlCti.Items.Count - 1;
}

}

}

}
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{

VisibleInputFields();
}

protected void ddlStt_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCti.Visible = true;
tbCity.Visible = false;
ddlCti.Items.Clear();

ListItemCollection licLocal =
Propertywala.Address.GetLocalCollection(long.Parse(ddlStt.SelectedValue),
true, "City");
foreach (ListItem li in licLocal)
{
ddlCti.Items.Add(li);
}


}
protected void ddlCti_SelectedIndexChanged(object sender, EventArgs e)
{
ddlLocal.Items.Clear();
if (ddlCti.SelectedValue.Length > 0 && ddlCti.SelectedValue != "0")
{
ListItemCollection licLocal =
Propertywala.Address.GetLocalCollection(long.Parse(ddlCti.SelectedValue),
true, "Locality");
foreach (ListItem li in licLocal)
{
ddlLocal.Items.Add(li);
}
ddlLocal.Visible = true;
tbLcl.Visible = false;
tbCity.Visible = false;
}
else
{
ddlLocal.Visible = false;
tbLcl.Visible = true;
if (ddlCti.SelectedIndex > 0)
{
tbCity.Visible = true;
}
}
tbLcl.Text = "";
tbPin.Text = "";
tbPin1.Text = "";
}
protected void ddlLocal_SelectedIndexChanged(object sender, EventArgs e)
{
tbLcl.Visible = false;
if (ddlLocal.SelectedValue.Length < 1 || ddlLocal.SelectedValue == "0")
{
if (ddlLocal.SelectedValue == "0")
{
tbLcl.Visible = true;
}
tbPin1.Text = "";
tbPin.Text = "";
}
else
{
tbPin1.Text =
Propertywala.Address.GetPincode(long.Parse(ddlLocal.SelectedValue));
tbPin.Text = tbPin1.Text;
}


}
private void VisibleInputFields()
{
bool isIndian = false;
if (ddlCountry.SelectedItem.Text == "India")
{
isIndian = true;
}
tbState.Visible = (!isIndian);
ddlStt.Visible = isIndian;
ddlCti.Visible = isIndian;
ddlLocal.Visible = isIndian;
tbPin.Visible = isIndian;
tbPin1.Visible = (!isIndian);
if (!isIndian)
{
tbLcl.Visible = true;
tbCity.Visible = true;
}
if (Page.IsPostBack)
{
ddlStt.SelectedIndex = -1;
ddlLocal.Visible = false;
ddlCti.Visible = false;
tbLcl.Text = "";
tbCity.Text = "";
tbPin.Text = "";
tbPin1.Text = "";
tbStr1.Text = "";
tbStr2.Text = "";
tbState.Text = "";
}
}

}
 

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top