开发者

ASP.NET - Edit CommandName on LinkButton using Javascript

I have a series of link buttons in a repeater that switch pages

<asp:Repeater ID="rptPageLinks" runat="server"><ItemTemplate>
    <asp:LinkButton ID="lnkNewPage" runat="server" Text='<%# Eval("Page") %>'
    OnCommand="SomeEventHandler" CommandArgument='<%# Eval("P开发者_JAVA百科age") %>' CommandName="Redirect"
    OnClientClick="return confirm('Do you want to save your chanes before you navigate to a new page?');" />
</ItemTemplate></asp:Repeater>

What I want to be able to do is pass the result from the OnClientClick into the EventHandler, ideally by changing the CommandName (i.e. if they click 'yes' on the confirmation it changes the CommandName to "SaveAndRedirect", if they click 'no' it stays as 'Redirect').

Can anyone help? Thanks if you can.


Unfortunately, what you ask is not possible in that way. OnCommand is an ASP.Net server side attribute of the asp control. On the client once rendered, you only have the client side html to work with.

The solution, however, is to save the value of the confirm dialog to your command event in a hidden field that you then read in your command. To do this, I would suggest something like:

<script type="text/javascript">
    function confirmSave() {
        document.getElementById('confirmChoice').value=confirm("Do you want to save your changes...");
    }
</script>
<input type='hidden' id='confirmChoice' runat="server" />

Then, within your page behind code called on the command event, you can access the value that was set into the hidden field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜