Click here to Skip to main content
15,887,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have a javascript function in my aspx code calling __doPostBack() function. In my code behind for this post back I update a selected item in a drop down list control depending on other control's value. The functionality is working fine but the postback is rendering the entire page and it is slow. I want to use an Updatepanel so that I only re-render the drop down list. Is it possible to somehow add a trigger to an UpdatePanel to link to this postback like the trigger to link to an control event? Or is there another way to achieve this?

Thanks in advance.

Like this:
XML
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
  <ContentTemplate>
      <asp:DropDownList ID="ddlItem1" runat="server" DataTextField="Item1" DataValueField="Item1">
      </asp:DropDownList>
  </ContentTemplate>
<Triggers>
      <asp:AsyncPostBackTrigger ControlID="ddlItem2" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
Posted

1 solution

1st method :: Javascript Code:
XML
function refreshddlItem2()
{
document.getElementById('<%= ddlItem2.ClientID %>').SelectedIndexChanged();
}

Add property to dropdownlist.
SQL
AutoPostBack="true"
onselectedIndexChanged="refreshddlItem2()"


2nd Method:
C#
protected void Page_PreRender(object sender, EventArgs e)
{

SQL
ClientScript.RegisterClientScriptBlock(typeof(Page), "UpdatePanelIDs", script, true);

}

3rd Method:
Add attributes to dropdownlist control and call the javascript function when it is necessary.
 
Share this answer
 
Comments
Dholakiya Ankit 7-Aug-13 23:26pm    
is it working?
Meg Takahashi 8-Aug-13 8:50am    
Hi Musakkhir,
Thanks for your reply! I am not able to use the 'SelectedIndexChanged' event as I am using 'onBlur' attribute. So I cannot use the 1st method. I want to handle the function to update another ddl value on the server side, so 3rd method is not suitable for my needs. (I'm calling my __doPostBack() in this way though.) I'm not sure how exactly the 2nd method works, but I will see if it is something I can do. I will let you know how it goes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900