Hi,
I have two drop down list. On each of these drop down's selection some code is there.
But page is taking too much time to call these events.
I have checked this within updatepanel and without updatepanel, but the result is same. How can I minimize the loading time.
Not : - 1st drop down has only 3 items and 2nd has only 4 items.
Total viewstate size - more than 300k
<asp:UpdatePanel runat="server" ID="upEntry" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlEntryForm" runat="server" Visible="false" Width="100%">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<span class="temptitle1">
<asp:Label ID="lblEntryFormTitle" runat="server">Create a new custom attribute</asp:Label></span>
</td>
<td class="error" align="right" style="padding-removed 5px;">
* Mandatory Fields
</td>
</tr>
<tr>
<td class="sectionBox" colspan="2">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="2" style="padding-removed 5px">
<asp:ValidationSummary ID="vsErrorSummary" runat="server" CssClass="error" DisplayMode="BulletList" />
</td>
</tr>
<tr>
<td>
<table border="0" width="100%" cellpadding="0" cellspacing="0" class="Grid">
<tr>
<td class="label" style="width: 20%">
Name <span class="error">*</span>
</td>
<td class="labelDescription">
<asp:TextBox ID="txtCustomAttributeName" runat="server" Width="250px" MaxLength="100"
CssClass="textbox" AutoCompleteType="Disabled" ToolTip="Custom Attribute Name"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvCustomAttributeName" runat="server" ControlToValidate="txtCustomAttributeName"
ErrorMessage="Name is required." Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="label" style="width: 20%">
Source <span class="error">*</span>
</td>
<td class="labelDescription">
<asp:DropDownList runat="server" ID="ddlSource" AutoPostBack="true" CssClass="dropdown"
OnSelectedIndexChanged="ddlSource_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvCustomAttributeSource" runat="server" ControlToValidate="ddlSource"
InitialValue="" ErrorMessage="Source is required." Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="label" style="width: 20%">
Data Type <span class="error">*</span>
</td>
<td class="labelDescription" style="width: 30%">
<asp:DropDownList runat="server" ID="ddlDataType" AutoPostBack="true" CssClass="dropdown"
OnSelectedIndexChanged="ddlDataType_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvDataType" runat="server" ControlToValidate="ddlDataType"
InitialValue="" ErrorMessage="Data Type is required." Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
<td class="label" style="width: 20%">
Control Type <span class="error">*</span>
</td>
<td class="labelDescription" style="width: 30%">
<asp:RadioButtonList runat="server" ID="rblControlType" RepeatDirection="Horizontal">
<asp:ListItem Selected="True" Text="Option" Value="O"></asp:ListItem>
<asp:ListItem Text="Drop Down" Value="D"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="width: 50%" class="">
<table runat="server" id="tblScaleLength" border="0" cellpadding="0" cellspacing="0"
width="100%" visible="false">
<tr>
<td class="label" style="width: 40%">
Scale / Length <span class="error">*</span>
</td>
<td class="labelDescription" style="width: 60%">
<asp:TextBox runat="server" ID="txtScaleLength" MaxLength="4" CssClass="numerictextbox"
Width="95%"></asp:TextBox>
<ajaxControls:FilteredTextBoxExtender ID="ftbeScaleLength" runat="server" FilterMode="ValidChars"
FilterType="Numbers" TargetControlID="txtScaleLength" />
<asp:RequiredFieldValidator ID="rfvScaleLength" runat="server" ControlToValidate="txtScaleLength"
ErrorMessage="Scale / Length is required." Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
</td>
<td runat="server" id="tdPrecision" style="width: 50%">
<table runat="server" id="tblPrecision" border="0" cellpadding="0" cellspacing="0"
width="100%" visible="false">
<tr>
<td class="label" style="width: 40%">
Precision <span class="error">*</span>
</td>
<td class="labelDescription" style="width: 60%">
<asp:TextBox runat="server" ID="txtPrecision" MaxLength="4" onblur="ChangePrecision(this);"
CssClass="numerictextbox" Width="95%"></asp:TextBox>
<ajaxControls:FilteredTextBoxExtender ID="ftbePrecision" runat="server" FilterMode="ValidChars"
FilterType="Numbers" TargetControlID="txtPrecision" />
<asp:RequiredFieldValidator ID="rfvPrecision" runat="server" ControlToValidate="txtPrecision"
ErrorMessage="Precision is required." Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator>
<asp:CompareValidator runat="server" ID="cmpScalePrecision" ControlToCompare="txtScaleLength"
ControlToValidate="txtPrecision" Operator="LessThanEqual" ErrorMessage="Precision should be less than scale / length."
Display="None" ValueToCompare=""></asp:CompareValidator>
<asp:CustomValidator ID="cvValidatePrecision" runat="server" Display="None" ClientValidationFunction="ValidatePrecision"></asp:CustomValidator>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width: 100%" colspan="2">
<table runat="server" id="tblMinMaxValue" border="0" cellpadding="0" cellspacing="0"
width="100%" visible="false">
<tr>
<td class="label" style="width: 20%">
Min. Value <span class="error">*</span>
</td>
<td class="labelDescription" style="width: 30%">
<asp:TextBox runat="server" ID="txtMinValue" MaxLength="20" onblur="CheckPrecision(this);"
CssClass="numerictextbox" Width="95%"></asp:TextBox>
<ajaxControls:FilteredTextBoxExtender ID="ftbeMinValue" runat="server" FilterMode="ValidChars"
FilterType="Numbers, Custom" ValidChars="-,." TargetControlID="txtMinValue" />
<asp:RequiredFieldValidator ID="rfvMinValue" runat="server" ControlToValidate="txtMinValue"
ErrorMessage="Minimum value is required." Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator>
<uc1:DateTextBox ID="dtbMinValue" runat="server" ClientJavascriptEvent="CheckDateRange();" />
</td>
<td class="label" style="width: 20%">
Max. Value <span class="error">*</span>
</td>
<td class="labelDescription" style="width: 30%">
<asp:TextBox runat="server" ID="txtMaxValue" MaxLength="20" onblur="CheckPrecision(this);"
CssClass="numerictextbox" Width="95%"></asp:TextBox>
<ajaxControls:FilteredTextBoxExtender ID="ftbeMaxValue" runat="server" FilterMode="ValidChars"
FilterType="Numbers, Custom" ValidChars="-,." TargetControlID="txtMaxValue" />
<asp:RequiredFieldValidator ID="rfvMaxValue" runat="server" ControlToValidate="txtMaxValue"
ErrorMessage="Maximum value is required." Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator>
<uc1:DateTextBox ID="dtbMaxValue" runat="server" ClientJavascriptEvent="CheckDateRange();" />
<asp:CustomValidator ID="cvValidateDates" runat="server" ClientValidationFunction="ValidateDates"
Display="None" Enabled="false"></asp:CustomValidator>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="label" style="width: 20%">
Active <span class="error">*</span>
</td>
<td class="labelDescription">
<asp:RadioButton ID="rbCustomAttributeIsActive" runat="server" Text="Yes" GroupName="CustomAttributeIsActive"
Checked="true" /><asp:RadioButton ID="rbCustomAttributeInactive" runat="server" Text="No"
GroupName="CustomAttributeIsActive" Checked="false" />
</td>
</tr>
<tr>
<td colspan="2" style="padding-removed 5px">
<asp:Panel runat="server" ID="pnlUserDefined" Visible="false">
<table border="0" cellpadding="0" cellspacing="0" width="50%">
<tr>
<td>
<div style="text-align: left">
<span class="temptitle1">User Defined Values</span></div>
</td>
</tr>
<tr>
<td>
<asp:Repeater ID="rptrUserDefined" runat="server" OnItemDataBound="rptrUserDefined_ItemDataBound">
<HeaderTemplate>
<table width="100%" cellpadding="0" cellspacing="1" border="0" class="box">
<tr>
<td style="width: 40%" align="left" class="GridHeaderTitle">
Code
</td>
<td style="width: 60%" align="left" class="GridHeaderTitle">
Value
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="GridItem">
<asp:TextBox runat="server" CssClass="textbox" MaxLength="20" ID="txtCode" Width="95%"></asp:TextBox>
<asp:HiddenField runat="server" ID="hfCustomAttributeValueID" />
</td>
<td class="GridItem">
<asp:TextBox runat="server" CssClass="textbox" Visible="false" ID="txtValue" Width="95%"></asp:TextBox>
<asp:TextBox runat="server" CssClass="numerictextbox" Visible="false" ID="txtInteger"
Width="95%"></asp:TextBox>
<ajaxControls:FilteredTextBoxExtender ID="ftbeInteger" runat="server" FilterMode="ValidChars"
FilterType="Numbers, Custom" ValidChars="-" TargetControlID="txtInteger" />
<asp:TextBox runat="server" CssClass="numerictextbox" Visible="false" ID="txtNumeric"
Width="95%"></asp:TextBox>
<ajaxControls:FilteredTextBoxExtender ID="ftbeNumeric" runat="server" FilterMode="ValidChars"
FilterType="Numbers, Custom" ValidChars="-,." TargetControlID="txtNumeric" />
<uc1:DateTextBox ID="dtbValue" Visible="false" runat="server" />
<asp:RadioButtonList runat="server" Visible="false" ID="rblBoolValue" RepeatDirection="Horizontal">
<asp:ListItem Text="Yes" Value="true" Selected="True"></asp:ListItem>
<asp:ListItem Text="No" Value="false"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<div style="text-align: right; width: 50%; padding-removed 5px; padding-removed 5px">
<asp:ImageButton ID="ibtnAddUserDefined" OnClick="ibtnAddUserDefinedValue_Click"
runat="server" ImageUrl="~/Graphics/Buttons/add.gif" AlternateText="Add" />
</div>
</asp:Panel>
<asp:Panel runat="server" ID="pnlSystemMaster" Visible="false">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<div style="text-align: left">
<span class="temptitle1">System Master</span></div>
</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="label" style="width: 20%">
Master <span class="error">*</span>
</td>
<td class="labelDescription" align="left" style="width: 30%">
<asp:DropDownList runat="server" ID="ddlMaster" Width="95%" AutoPostBack="true" CssClass="dropdown"
OnSelectedIndexChanged="ddlMaster_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ControlToValidate="ddlMaster" ID="rfvMaster"
InitialValue="" Display="None" Enabled="false" ErrorMessage="Master is required."></asp:RequiredFieldValidator>
</td>
<td colspan="2" class="label">
</td>
</tr>
<tr>
<td class="label" style="width: 20%">
Key Column <span class="error">*</span>
</td>
<td class="labelDescription" align="left" style="width: 30%">
<asp:DropDownList runat="server" ID="ddlKeyColumn" onchange="SelectDataType(this);"
Width="95%" CssClass="dropdown">
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ControlToValidate="ddlKeyColumn" ID="rfvKeyColumn"
InitialValue="" Display="None" Enabled="false" ErrorMessage="Key Column is required."></asp:RequiredFieldValidator>
</td>
<td class="label" style="width: 20%">
Display Column <span class="error">*</span>
</td>
<td class="labelDescription" align="left" style="width: 30%">
<asp:DropDownList runat="server" ID="ddlDisplayColumn" Width="95%" CssClass="dropdown">
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ID="rfvDisplyColumn" ControlToValidate="ddlDisplayColumn"
InitialValue="" Display="None" Enabled="false" ErrorMessage="Display Column is required."></asp:RequiredFieldValidator>
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
</td>
</tr>
</table>
<asp:CustomValidator runat="server" ID="cvValidate" Enabled="false" ClientValidationFunction="Validate"
Display="None"></asp:CustomValidator>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel<small></small>>
Calling below methods on selectionindexchanged of drop down
private void LoadFieldsAsPerDataType(CustomAttribute customAttribute)
{
tdPrecision.Attributes.Add("class", "");
if (string.IsNullOrEmpty(ddlDataType.SelectedValue) || ddlSource.SelectedValue == "S")
{
tblScaleLength.Visible = tblPrecision.Visible = tblMinMaxValue.Visible = false;
return;
}
rfvMaxValue.Enabled = rfvMinValue.Enabled = cvValidateDates.Enabled = false;
if (ddlSource.SelectedValue == "F")
{
switch (ddlDataType.SelectedItem.Text.ToLower())
{
case "date":
{
tblScaleLength.Visible = tblPrecision.Visible = txtMinValue.Visible = txtMaxValue.Visible = false;
tblMinMaxValue.Visible = dtbMaxValue.Visible = dtbMinValue.Visible = true;
dtbMaxValue.Date = dtbMinValue.Date = null;
txtScaleLength.Text = string.Empty;
txtPrecision.Text = string.Empty;
txtMinValue.Text = txtMaxValue.Text = string.Empty;
txtScaleLength.Enabled = true;
cvValidateDates.Enabled = true;
if (customAttribute != null)
{
dtbMinValue.Date = Convert.ToDateTime(customAttribute.CustomAttributeMinimumValue);
dtbMaxValue.Date = Convert.ToDateTime(customAttribute.CustomAttributeMaximumValue);
}
}
break;
case "integer":
{
tblScaleLength.Visible = tblPrecision.Visible = dtbMaxValue.Visible = dtbMinValue.Visible = false;
tblMinMaxValue.Visible = txtMinValue.Visible = txtMaxValue.Visible = true;
txtMinValue.Text = txtMaxValue.Text = string.Empty;
txtScaleLength.Text = string.Empty;
txtPrecision.Text = string.Empty;
dtbMinValue.Date = dtbMaxValue.Date = null;
txtScaleLength.Enabled = true;
rfvMaxValue.Enabled = rfvMinValue.Enabled = true;
if (customAttribute != null)
{
txtMinValue.Text = customAttribute.CustomAttributeMinimumValue.ToString();
txtMaxValue.Text = customAttribute.CustomAttributeMaximumValue.ToString();
}
}
break;
case "numeric":
{
dtbMaxValue.Visible = dtbMinValue.Visible = false;
tblScaleLength.Visible = tblPrecision.Visible = tblMinMaxValue.Visible = txtMinValue.Visible = txtMaxValue.Visible = true;
txtPrecision.Text = txtMinValue.Text = txtMaxValue.Text = txtScaleLength.Text = string.Empty;
dtbMinValue.Date = dtbMaxValue.Date = null;
txtScaleLength.Enabled = true;
rfvMaxValue.Enabled = rfvMinValue.Enabled = true;
if (customAttribute != null)
{
txtMinValue.Text = customAttribute.CustomAttributeMinimumValue.ToString();
txtMaxValue.Text = customAttribute.CustomAttributeMaximumValue.ToString();
txtScaleLength.Text = customAttribute.CustomAttributeScale.HasValue ? customAttribute.CustomAttributeScale.Value.ToString() : string.Empty;
txtPrecision.Text = customAttribute.CustomAttributePrecision.HasValue ? customAttribute.CustomAttributePrecision.Value.ToString() : string.Empty;
}
}
break;
case "boolean":
{
tblPrecision.Visible = tblMinMaxValue.Visible = txtMinValue.Visible = txtMaxValue.Visible = dtbMaxValue.Visible = dtbMinValue.Visible = false;
tblScaleLength.Visible = true;
txtScaleLength.Text = one;
txtPrecision.Text = txtMinValue.Text = txtMaxValue.Text = string.Empty;
dtbMinValue.Date = dtbMaxValue.Date = null;
txtScaleLength.Enabled = false;
ddlSource.SelectedValue = "F";
tdPrecision.Attributes.Add("class", "label");
if (customAttribute != null)
txtScaleLength.Text = customAttribute.CustomAttributeScale.HasValue ? customAttribute.CustomAttributeScale.Value.ToString() : one;
}
break;
case "text":
{
tblPrecision.Visible = tblMinMaxValue.Visible = txtMinValue.Visible = txtMaxValue.Visible = dtbMaxValue.Visible = dtbMinValue.Visible = false;
tblScaleLength.Visible = true;
txtPrecision.Text = txtMinValue.Text = txtMaxValue.Text = txtScaleLength.Text = string.Empty;
dtbMinValue.Date = dtbMaxValue.Date = null;
txtScaleLength.Enabled = true;
tdPrecision.Attributes.Add("class", "label");
if (customAttribute != null)
txtScaleLength.Text = customAttribute.CustomAttributeScale.HasValue ? customAttribute.CustomAttributeScale.Value.ToString() : string.Empty;
}
break;
}
}
if (ddlSource.SelectedValue == "U")
{
tblScaleLength.Visible = tblPrecision.Visible = tblMinMaxValue.Visible = false;
tdPrecision.Attributes.Add("class", "");
if (customAttribute != null)
this.BindUserDefinedValues(customAttribute.CustomAttributeValues);
else
this.BindUserDefinedValues(null);
}
}
private void LoadFieldsAsPerSource(CustomAttribute customAttribute)
{
if (string.IsNullOrEmpty(ddlSource.SelectedValue))
{
pnlSystemMaster.Visible = pnlUserDefined.Visible = false;
ddlDataType.Enabled = true;
return;
}
ddlDataType.Enabled = true;
cvValidate.Enabled = rfvMaster.Enabled = rfvKeyColumn.Enabled = rfvDisplyColumn.Enabled = false;
rfvDataType.Enabled = true;
if (ddlDataType.Items.FindByText("Boolean") != null)
ddlDataType.Items.FindByText("Boolean").Enabled = true;
if (ddlSource.SelectedValue == "U")
{
pnlUserDefined.Visible = true;
pnlSystemMaster.Visible = false;
cvValidate.Enabled = true;
tblPrecision.Visible = tblMinMaxValue.Visible = tblScaleLength.Visible = false;
ddlDataType.Items.FindByText("Boolean").Enabled = false;
if (ddlDataType.SelectedItem.Text == "Boolean")
{
ddlDataType.SelectedValue = string.Empty;
this.LoadFieldsAsPerDataType(customAttribute);
}
if (customAttribute != null)
this.BindUserDefinedValues(customAttribute.CustomAttributeValues);
else
this.BindUserDefinedValues(null);
}
else if (ddlSource.SelectedValue == "S")
{
pnlUserDefined.Visible = false;
pnlSystemMaster.Visible = true;
ddlDataType.Enabled = false;
tblPrecision.Visible = tblMinMaxValue.Visible = tblScaleLength.Visible = false;
rfvMaster.Enabled = rfvKeyColumn.Enabled = rfvDisplyColumn.Enabled = true;
rfvDataType.Enabled = false;
tdPrecision.Attributes.Add("class", "");
}
else
{
pnlUserDefined.Visible = pnlSystemMaster.Visible = false;
this.LoadFieldsAsPerDataType(customAttribute);
}
}