Optimize Ajax Response time [Resolved]

Posted by Riyazhaider under JavaScript on 12/7/2013 | Points: 10 | Views : 1772 | Status : [Member] | Replies : 2
I m populating values in 6 combo on change on 1 combo using ajax with javascript,
when i change combo then it takes time to populate values in 6 combo but during this time web page looks hang. how to optimize response time.




Responses

Posted by: vishalneeraj-24503 on: 12/7/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Are you hitting db on every dropdown selectedindexchanged? if yes. then what you have to do.
Please store your data in viewstate. and on selectedindexchanged event,fill other dropdownlists from your viewstate based on the selected value.

You can use dataset/datatable Select method.
So it's one time activity to store all your data in viewstate in page load.
And with the help of Select method,you can pass values.
For ex:-

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");

dt.Rows.Add("1", "Vishal");
dt.Rows.Add("2", "Rajesh");
dt.Rows.Add("3", "Prashant");
dt.Rows.Add("4", "Dharmesh");
dt.Rows.Add("5", "Nitin");


DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Id";
DropDownList1.DataBind();

ViewState["DataTeable"] = dt;
}
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DropDownList2.Items.Clear();
if (ViewState["DataTeable"] != null)
{
DataTable dt = (DataTable)ViewState["DataTeable"];
if (dt != null)
{
if (dt.Rows.Count > 0)
{
DataRow[] dr = dt.Select("Id='" + DropDownList1.SelectedValue + "'");
if (dr != null)
{
if (dr.Length > 0)
{
DataTable dt_new = dr.CopyToDataTable();
DropDownList2.DataSource = dt_new;
DropDownList2.DataTextField = "Name";
DropDownList2.DataValueField = "Id";
DropDownList2.DataBind();
}
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}


Riyazhaider, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Riyazhaider on: 12/10/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks vishal it works.

Riyazhaider, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response