asp dropdownlist postback not working in update panel when using <base> url in masterpage
Asked Answered
B

3

7

I am using, <base href="http://localhost:80/"> in my master page for base url,

now when I am using dropdownlist control on content page (located in localhost:80/directory1/directory2) within update panel, selectedindexchanged event is not working.

I tried to figure out, but in network tab of firefox console I found that request is looking for content page at base url only that is at localhost:80/contenpage.aspx instead of localhost:80/directory1/directory2/contenpage.aspx and giving error

The resource cannot be found.

Benzo answered 28/1, 2016 at 2:23 Comment(5)
did you set autopostback to true?Versicular
yes, I did and if I comment that base tag in masterpage everything works fineBenzo
#11521511 ___ please check if the above post works. Looks like it has something to do with absolute path and relative pathSpessartite
Hi @user2846413 above post solved my other issues of relative urls but my actual problem still persists.. still dropdownlist event is not getting fired.. because we do not supply any url to that event, I had binded server side event simply like we do in normal code..Benzo
Can you show us your .aspx and code-behind?Sclerenchyma
B
2

The relevant circumstance is that the form action is set to a relative URL in ASP.NET by default:

<form id="ctl01" action="./webform1" method="post">
    <!-- ... -->
</form>

If you use the base tag, you change the base path that the page uses to interpret relative URLs. In your case, the base URL points to a path that is obviously not able to serve the pages of the application. In order to fix this, I'd reconsider whether the base tag is necessary. If it is, it should point to a URL that is able to serve the pages of the application. In order to set the base path to the base path of the application dynamically, you can use the following code:

protected void Page_Load(object sender, EventArgs e)
{
    baseCtrl.Attributes["href"] = new Uri(Request.Url, "/").OriginalString;
}

As a work-around if you need to keep the base tag as it is, I've also tried to set the form action to an absolute URL by integrating the following code into the master page:

protected void Page_Load(object sender, EventArgs e)
{
    Page.Form.Action = Request.Url.OriginalString;
}

This worked in my small sample so that the page could execute the PostBack successfully. Though the form is posted back to the same location as if there was no base tag, there might be some side-effects because other resources on the page (e.g. CSS, JavaScript files and the like) might also be referenced with a relative URL and therefore be retrieved from another location. So I'd still propose to reevaluate the base tag before resorting to this solution.

Blunt answered 18/2, 2016 at 19:30 Comment(0)
O
1

if you have some asp component with Autopostback="true" and ClientIdMode="Static", you have to use the triger!

like this:

<asp:UpdatePanel ID="upPrinceOffuce" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="myCustomDropdown" EventName="SelectedIndexChanged" />
    </Triggers>
    <ContentTemplate>
         <asp:DropDownList ID="myCustomDropdown" runat="server" ClientIDMode="Static" AutoPostBack="true"
</asp:DropDownList>
    </ContentTemplate>
</asp:UpdatePanel>
Oscillogram answered 18/2, 2016 at 18:35 Comment(0)
L
1

Try specifiing absolute url in form's action.

Leading answered 18/2, 2016 at 18:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.