Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top