on my main page f...">

Asp dropdownlist postback not working in update panel when using <base> url on main page

I use <base href="http://localhost:80/"> on my main page for the base url,

Now when I use the dropdownlist control on the content page (located in localhost:80/directory1/directory2 ) in the update panel, the selectedindexchanged event does not work.

I tried to find out, but on the network tab in the firefox console I found that the request only looks for the page with the url base, which is in localhost:80/contenpage.aspx instead of localhost:80/directory1/directory2/contenpage.aspx and gives an error

Resource is not found.

+7
c # drop-down-menu updatepanel selectedindexchanged
source share
3 answers

The relevant circumstance is that the action of the form is set in relation to the 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 used by this page to interpret relative URLs. In your case, the URL base points to a path that obviously cannot serve the pages of the application. To fix this, I would reconsider if a base tag is needed. If so, it should provide a URL that can serve the pages of the application. 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 workaround, if you need to keep the base tag as is, I also tried to set the form action to an absolute URL by integrating the following code on the main 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 successfully execute PostBack. Although the form is sent back to the same place as where there was no base tag, there may be some side effects, because other resources on the page (such as CSS, JavaScript files, etc.) can also link to a relative URL and therefore removed from another place. Therefore, I still suggest re-evaluating the base tag before resorting to this solution.

+2
source share

if you have an asp component with Autopostback = "true" and ClientIdMode = "Static", you should use 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> 
+1
source share

Try specifying an absolute URL in the form of action .

+1
source share

All Articles