0

Coders,

I have an asp.net dropdownlist control with an AutoPostBack=True. The control is placed on an html/javascript tab container on the defautl page URL is /Default.aspx. In order to interact with the dropdownlist and fire the AutoPostBack the user must select tab item # 2 which changes the URL of the page to /default.aspx#content-tab-1-2-tab. This is becuase the dropdownlist is placed in the tab item #2 and it is not visible with the user visit /default.aspx .

Now the problem is that whenever the page post back, due to the selection change in the dropdownlist, the page will point to /default.aspx URL and not /default.aspx#content-tab-1-2-tab URL. This causes the dropdownlist to not be visible and the user has to click on the tab item #2 to interact with the dropdownlist again.

How do I force the AutoPostBack action in the dropdownlist to point to /default.aspx#content-tab-1-2-tab and not /default.aspx ?

And here is a snippet from my code

protected void Page_Load(object sender, EventArgs e)
{
    DropDownList_City.Enabled = false;
    DropDownList_District.Enabled = false;


    GMap_main.addControl(new GControl(GControl.extraBuilt.MarkCenter));
    GMap_main.addControl(new GControl(GControl.extraBuilt.TextualCoordinatesControl));
    GMap_main.enableGoogleBar = true;
    GMap_main.Language = "ar";


    if (!IsPostBack)
    {
        var countries = from x in db.Countries select x.name_ar;

        //BINDING THE DROP DOWN LIST
        DropDownList_Country.DataSource = countries;
        DropDownList_Country.DataBind();

        DropDownList_City.Enabled = false;
        DropDownList_District.Enabled = false;
    }

}

/// <summary>
/// EVENT HANDLING FOR THE DROP DOWN LIST
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DropDownList_Country_SelectedIndexChanged(object sender, EventArgs e)
{
    var city = from x in db.Cities where x.Country.name_ar == DropDownList_Country.SelectedValue select x.name_ar;

    DropDownList_City.DataSource = city;
    DropDownList_City.DataBind();

    DropDownList_City.Enabled = true;

}

Thank you.

Eyad
  • 13,440
  • 6
  • 26
  • 43
  • Are you redirecting the user based on the selection? The postback should not change the url. – Khan Apr 13 '12 at 19:49
  • No, I always redirect the user no matter what the user select. – Eyad Apr 13 '12 at 19:52
  • Then it is not your postback which is your issue, it is your redirect. – Khan Apr 13 '12 at 19:53
  • let me clarify what I mean... I have an unconditional AutoPostBack in my dropdownlist. Hence, the Post Back (i.e. redirection) will always occurs no matter what the user select. And after the post back the page URL become /default.aspx which hide the tab item that contain the dropdownlist. – Eyad Apr 13 '12 at 20:00
  • I mean do you `Response.Redirect("default.aspx");` in your `ddl_SelectedIndexChanged()` ? – Khan Apr 13 '12 at 20:04
  • No. I have updated my question to show the relevant code. – Eyad Apr 13 '12 at 20:11

1 Answers1

1

Because the fragment portion of the URL (the part after and including the #) isn't sent to the server, you're going to have a harder time solving this problem than it might seem like you should. One way to fix it would be to add some javascript that sets the value of a hidden field when you change tabs. Then when it posts back, you'll know what page you were on and you can include the fragment as part of your redirect.

Katie Kilian
  • 6,815
  • 5
  • 41
  • 64
  • the problem is still that I can not change the URL of the auto post back. So even though i know that the dropdownlist is place on /default.aspx#content-tab-1-2-tab, I can not force the post back url to be /default.aspx#content-tab-1-2-tab. It will always post back to /default.aspx And if use Response.Redirect("/default.aspx#content-tab-1-2-tab") after the selection has changed, then I lose all the selected data on the dropdownlist. – Eyad Apr 13 '12 at 21:02
  • You can't post back to the URL like you want to -- the # and everything after it is not included in the query to the server. It is purely client side. Browsers simply don't send it. You will have to fix the problem another way. – Katie Kilian Apr 13 '12 at 21:10