Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to dropDown Value Remain After Refresh Page i mention below Code

What I have tried:

C#
void BindState()
   {
       DCI_Assign_Inspectors_DetailsClient client = new DCI_Assign_Inspectors_DetailsClient();
       DataSet ds = new DataSet();
       Prop objprop = new Prop();
       client.Open();
       objprop.Mode = "1";
       objprop.StateCode = "";

       try
       {
           ds = client.BindState(objprop);

           if (ds.Tables[0].Rows.Count > 0)
           {
               DrpState.DataSource = ds;
               DrpState.DataTextField = "State_Name";
               DrpState.DataValueField = "State_Code";
               DrpState.DataBind();
               DrpState.Items.Insert(0, new ListItem("--Please Select--", "All"));
           }

       }
       catch (Exception ex)
       {
           ScriptManager.RegisterStartupScript(Page, Page.GetType(), "InvalidArgs", "alert(" + ex.Message + ");", true);

       }
       finally
       {
           ds.Dispose();
           client.Close();
           objprop = null;
       }
   }
Posted
Updated 11-Jul-16 0:33am
v3
Comments
F-ES Sitecore 11-Jul-16 5:41am    
Don't call "BindState" when it is a postback.

When you click the refresh button, it will reload the page, and the IsPostBack property becomes false.
so it cant be handled in Server,
but using Client storage mechanism[^] you shall achieve this

refer this Retain selected value for link dropdown upon refresh [^]
 
Share this answer
 
I suspect, you have called the BindState() in the Page_Load() event but haven't emebeded it inside IsPostBack check.
If so, please try wrapping your BindState() call inside IsPostBack proprty check, somethi ng like following-
C#
if(!Page.IsPostBack)
    BindState();


It will bind the dropdown on first load and on postback the function call will not be hit so the issue should be resolved.

Hope, it helps :)
 
Share this answer
 
v2

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