Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
25
How to access web dropdown selected item value on server side code
posted

Hi All,

I am using WebAsyncRefreshPanel, UltrawebGrid and WebDropDown controls on page.

I have input html button outside the WebAsyncRefreshPanel.
WebGrid is inside the WebAsyncRefreshPanel.

I am using WebAsyncRefreshPanel content refresh event to call server side method asynchronously.

From the dropdwon I select values and click on button which is outside refresh panel.
I am calling content refresh server side event using this


  var warp = ig$("<%=WebAsyncRefreshPanel1.ClientID %>");
        if(!warp){return;}
        warp.refresh();

Inside cintent refresh event I am calling BuildGrid function
I need dropdown values to pass to server and fetch data

protected void wrappnlGrid_ContentRefresh(object sender, EventArgs e)
    {
        try
        {
            if (Session["BuildGrid"] != null)
            {
                pnlGridContent.Visible = false;
                if (Convert.ToBoolean(Session["BuildGrid"]))
                {
                    hdnEditableRowIDs.Value = string.Empty;
                    BuildGrid();
                    Session["BuildGrid"] = false;
                }
                else
                {
                    Session["BuildGrid"] = true;
                }
            }
            else
            {

                Session["BuildGrid"] = true;
            }

            //if (hdnSaveOrBuild.Value == "BuildGrid")
            //{
            //    //status.Text = "wrappnlGrid_ContentRefresh";     
            //    BuildGrid();
            //    hdnSaveOrBuild.Value = string.Empty;
            //}
        }
        catch (Exception ex)
        {
            string ErrorLocation = "NonWorkFlowSheetNoMaster.aspx.cs : wrappnlGrid_ContentRefresh()";
            ClsErrorLog.LogError(ErrorLocation, ex);
            ErrorHandler.HandleExceptionNoRedirect(ex);
        }
    }

I am not getting values of dropdown inside build grid function

    private void BuildGrid()
    {
        try
        {
            pnlGridContent.Visible = false;
            int AccountId = 0;
            int YearId = Convert.ToInt32(ddlYear.SelectedItem.Value);
            int VersionId = Convert.ToInt32(ddlVersion.SelectedItem.Value);
            int DimensionId = Convert.ToInt32(ddlDimension.SelectedItem.Value);
            int UnitId = 0;
            string Template = ddlTemplate.SelectedItem.Value;
            string IdList = string.Empty;
            if (ddlTemplate.SelectedItem.Value.Trim().ToLower() == "account")
            {
                AccountId = Convert.ToInt32(ddlAccounts.SelectedItem.Value);
                IdList = hdnEntityValue.Value;
            }
            else if (ddlTemplate.SelectedItem.Value.Trim().ToLower() == "unit")
            {
                UnitId = Convert.ToInt32(ddlUnit.SelectedItem.Value);
                IdList = hdnAccountValue.Value;
            }

            bool IsTotalVisible = chkShowTotal.Checked;


            DataTable dtGrid = null;

            dtGrid = GetData(AccountId, YearId, VersionId, DimensionId, UnitId, Template, IdList);
            if (IsTotalVisible)
            {
                AddTotalRowAndColumn(dtGrid);
            }
            //status.Text = "BuildGrid";
            //CreateTable(dtGrid);
            if (dtGrid != null && dtGrid.Rows.Count > 0)
            {
                //status.Text = "BuildGridNotNull";
                ultNWGrid.Clear();
                ultNWGrid.DataSource = dtGrid;
                ultNWGrid.DataBind();
                pnlGridContent.Visible = true;
            }
            else
            {
                ultNWGrid.Clear();
                ultNWGrid.DataSource = null;
                ultNWGrid.DataBind();
                pnlGridContent.Visible = false;
            }
        }
        catch (Exception ex)
        {
            string ErrorLocation = "NonWorkFlowSheetNoMaster.aspx.cs : BuildGrid()";
            ClsErrorLog.LogError(ErrorLocation, ex);
            ErrorHandler.HandleExceptionNoRedirect(ex);
        }
    }

Can anybody please help me out
(ddlYear.SelectedItem.Value) to get value

  • 19693
    Suggested Answer
    posted

    Hello Charles,

    The issue happens becuase you are accessing the SelectedItem inside ContentRefresh event of the WARP.

    I suggest you doing post back.

    Another option is setting the ID of the WebDropDown as RefreshTargetIDs and setting the RefreshInterval to zero which I strongly do not recommend you.

     

    <igmisc:WebAsyncRefreshPanel ID="WebAsyncRefreshPanel1" runat="server" Height="20px"

                Width="80px" OnContentRefresh="WebAsyncRefreshPanel1_ContentRefresh"

                RefreshTargetIDs="WebDropDown1"  RefreshInterval="0">

    Hope this helps