2
votes

I have an ext:button. I want to trigger it's OnClick event by JavaScript based on the condition of a confirm message.

My Button

<ext:Button ID="btnAddEsya" Text="text" runat="server" Icon="Add" >
    <DirectEvents>
        <Click OnEvent="btnAddEsya_Click" ViewStateMode="Enabled">
        </Click>
    </DirectEvents>
</ext:Button>

Code Behind (only relevant parts)

[DirectMethod]
    public void btnAddEsya_Click(object sender, EventArgs e)
    {
     if (/*Checking conditions here*/)
        {
            X.Msg.Confirm("Warning", "Save?", new JFunction { Fn = "SaveLine" }).Show();
        }

}

Java Script

<script language="javascript" type="text/javascript">
        var SaveLine = function (btn) {
            if (btn == 'yes') {
                alert('TEST YES');
                NewLine.click();
                document.getElementById('btnAddEsya').click();


            }
            else if (btn == 'no')
            { alert('TEST NO'); }
        };
            </script>

So far I tried this method, the __doPostBack('btnAddEsya','OnClick'); method and assigning the buttons to variables and calling them as variablename.click(). None of them worked.

Can it be about ext.net buttons Click OnEvent ?

Edit:

Recently I tried this too, and it didn't work either. Also

<script language="javascript" type="text/javascript">
        btnAddEsya = document.getElementById('<%= btnAddEsya.ClientID %>');
        var SaveLine = function (btn) {
            if (btn == 'yes') {
                alert('TEST YES');
                btnAddEsya.click();
                }
            else if (btn == 'no')
            { alert('TEST NO'); }
        };
            </script>
2

2 Answers

0
votes

Could you try something like this?

#{btnAddEsya}.fireEvent("click");
0
votes

Oh ok, I'm sorry, I thought that you wanted to call a javascript click event, my mistake.

Try this code in your button:

<DirectEvents>
    <Click OnEvent="btnAddEsya_Click" ViewStateMode="Enabled">
        <Confirmation ConfirmRequest="true" Title="Warning" Message="Save?" />
    </Click>
</DirectEvents>

It will ask for confirmation before calling your DirectEvent.