Currently, I am working with ASP.NET and have a link that utilizes both onclick and onserverclick events. While both are crucial, I would like the onclick event to override the onserverclick event if possible.
This is the code snippet I am currently experimenting with:
<ul class="clickables">
<asp:Repeater ID="MenuRepeater" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<li class=" <%# ((DataRowView)Container.DataItem)["CSSClass"]%>"
style="background-color: <%# ((DataRowView)Container.DataItem)["BackgroundColour"]%>">
<a id="A1"
runat="server"
onserverclick="LinkClick"
onclick=<%# "return javascript:LinkClick('" + ((DataRowView)Container.DataItem)["Postback"] + "')" %>
customid='<%# ((DataRowView)Container.DataItem)["UniqueID"]%>'
href='<%# ((DataRowView)Container.DataItem)["PageFile"]%>'>
</a>
<%# ((DataRowView)Container.DataItem)["DisplayName"]%>
</li>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</ul>
Here's the JavaScript logic I'm using in an attempt to prevent the postback:
function LinkClick(parameters) {
if (parameters[0] == "False") {
return false;
}
Could there be something missing in my implementation? Is it feasible to halt the onserverclick event from firing? I know that returning false in onclick can prevent a regular postback, but what about onserverclick?
Update Upon further debugging (after being out of web development for some time), it seems that the JS function isn't triggering...
Update 2
Shown below is the complete rendered page source:
... (full rendered page source omitted for brevity) ...Edit 3
Even when I do:
onclick='return LinkClick(False)'
OR
onclick="return LinkClick(False)"
I still get:
onclick="return LinkClick('True')"
Edit 4
Here is the current rendered source:
... (more rendered source details included here) ...Update 5
So if I leave the method and simply return true/false, should it stop the postback? Even this doesn't work (additional rendered source provided).
... (further updates and source code analysis continue) ...