locked
Dropdown in a thickbox popup RRS feed

  • Question

  • User183689629 posted

    Hi guys,

    I have a drop down list in a thickbox pop-up window. When i do a postback to filter the results in this window, for some reason, the dropdown list is re-created and I lose the selection. The list is created only the first time and even when I put in a breakpoint at teh function that creates this list, I only hit it once, when the page is created the first time. However, for some weird reason, I still end up with a list that's recreated on postback. As usual, I make it as 

    if (!ipostback)

    CreateList();


    private void CreateList()

    {..create the list}

    Need help :)

    Tuesday, October 27, 2009 2:15 PM

Answers

  • User183689629 posted

    sorted, it was a linq function.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 2, 2009 8:56 AM

All replies

  • User-2070791419 posted

    How are you posting back to the server? Js or the OnSelectedIndexChanged od the DropDown



    Tuesday, October 27, 2009 3:30 PM
  • User183689629 posted

    Hi, I am using a button for postback

    Tuesday, October 27, 2009 3:46 PM
  • User-2070791419 posted

    Can you post your aspx code? 

    Tuesday, October 27, 2009 4:26 PM
  • User183689629 posted

    Hi,

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    GetAllSectors();protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    GetAllSectors();

    protected void Page_Load(object sender, EventArgs e)

            {

                if (!IsPostBack)

                {

                    GetAllSectors();

                }

    }


    private void GetAllSectors()

            {

                var sectors = Db.sp_get_sectors_list();            

                drpSectors.DataSource = sectors;                

                drpSectors.DataTextField = "Name";

                drpSectors.DataValueField = "SectorId";

                drpSectors.DataBind();

            }

    private void SearchArticles()

            {

                int sectorId = Convert.ToInt16(drpSectors.SelectedValue);

                gridResults.DataSource = Db.sp_browse_articles(sectorId);

                gridResults.DataBind();

            }


    The SectorId in the above function always gets me the first item in the list as indicated above, it just ignores anything you have selected prior to the postback.

    This happens only in a thickbox iframe window, but works fine otherwise.

    Tuesday, October 27, 2009 5:33 PM
  • User-2070791419 posted

    Please post your aspx code?

    Wednesday, October 28, 2009 10:14 AM
  • User-474980206 posted

    thickbox like many of the jquery popups does not support form fields in the popup. they will not post back, because when the popup is displayed, the content is removed from the form collection (in the case of ie6, the window). you can put a <form></form> in the popup content, and postback from the popup will only post the fields in the popup.

    you should use a little javascript to move the selected value to a hidden field. then on postback you can apply the value to the server control.


    Wednesday, October 28, 2009 11:21 AM
  • User183689629 posted

    <asp:DropDownList runat=server ID="drpSectors"></asp:DropDownList> 
                    <asp:LinkButton runat=server ID="lnkFilter" Text="Filter" 
                        onclick="lnkFilter_Click" OnClientClick="doPostBack(this)" ></asp:LinkButton>

    Hi, here's the code.


    <form id="form1" runat="server">

    <asp:DropDownList runat=server ID="drpSectors"></asp:DropDownList> 

                    <asp:LinkButton runat=server ID="lnkFilter" Text="Filter" 

                        onclick="lnkFilter_Click"></asp:LinkButton>

    </form>

    Wednesday, October 28, 2009 7:19 PM
  • User183689629 posted

    Hi Bruce, I have a datagrid on that page and the paging works like a charm (this also uses postback). Funnily enough, if I just run this as a standard page in the browser, I still see the same problem, the drop down being recreated!

    For another test, I put up another dropdown control with fixed item collections defined on the surface and that maintained the selection on postbacks, but as soon as I get the server to create the dropdown items, even that goes bonkers!!

    Added button and even that doesn't work. Really lost now...

    Wednesday, October 28, 2009 7:31 PM
  • User183689629 posted

    sorted, it was a linq function.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 2, 2009 8:56 AM