Alex
Alex

Reputation: 3968

asp LinkButton _doPostBack

I have the following menu:

<header class="logged-in clearfix" runat="server" id="hdrLoggedIn" visible="false">
    <div class="container">
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li runat="server" ID="liLoggedIn"><asp:LinkButton runat="server" ID="btnLoggedIn" OnClick="btnLoggedIn_Click" CausesValidation="false" /></li>
                <li runat="server" ID="liChangePwd"><asp:LinkButton runat="server" ID="btnChangePwd" Text="Change Password" OnClick="btnChangePwd_Click" CausesValidation="false" /></li>
                <li runat="server" ID="liIdUpload"><asp:LinkButton runat="server" ID="btnIdUpload" Text="ID Upload" OnClick="lnkIdUpload_Click" CausesValidation="false" /></li>    
                <li runat="server" ID="liAdmin"><asp:LinkButton runat="server" ID="btnAdmin" Text="Admin" OnClick="btnAdmin_Click" CausesValidation="false" /></li>     
                <li runat="server" ID="liLogout"><asp:LinkButton runat="server" ID="btnLogout" Text="Logout" OnClick="btnLogout_Click" CausesValidation="false" /></li>
                <li runat="server" ID="liUnsub"><a href="unsubscribe.aspx">Unsubscribe User</a></li>
                <li runat="server" ID="liPerfMon"><a href="adminmonitor.aspx">Performance Monitor</a></li>
            </ul>
        </div>
    </div>
</header>

And this in developer tools:

enter image description here

Which leads me to believe that asp.net is adding in the _doPostBack function (unless I am missing something as I did not make this application).

This is a global header menu declared in the master page.

My problem is that, the menu works fine on all the pages except one particular page.

I have tried adding a Response.Write to the onClick method, but this does not get triggered, which leads me to believe that the onClick is not getting fired.

If it is not getting fired, it seems the most obvious possibility is that the _doPostBack is somehow failing and preventing the onClick method from firing?

If this is the case, or sounds sensible to anyone, why is this happening, and what can I do to resolve it.

Possibly something in the page it is not working or is conflicting with the _doPostBack ? Or something else?

Any ideas?

Upvotes: 0

Views: 711

Answers (1)

xxxmatko
xxxmatko

Reputation: 4142

When you assign OnClick property, you assign event handler for the Click event of the target control. So in your example I assume that you have implemented server method btnChangePwd_Click in your code behind. To trigger this method, the rendered page must be sent to the server using POST method - you have form on your page. Because asp:LinkButton is rendered in the resulting HTML as a element, and this element does not trigger posting of the form, ASP.NET renders special helping method __doPostBack which is a simple javascript function, which takes its input argument (the input argument is the id of the element which is triggering the postback) set this argument as a value for the hidden field in the form, and then it sends the form. On the server side, according to the value which was supplied as in input argument, .NET knows which server function should be called.

So if your menu does not work only on one particular page, check if you do not have some javascript error on the page, or some mismatched html code rendered, which can destroy all this logic.

Upvotes: 1

Related Questions