简体   繁体   中英

Calling a button click function using javascript in c#

Hi I am trying to call a button click function written within the c# code behind from javascript. but its not triggering the button click function. I didnt find anything suspicious in the code. Please check and let me know what is actually blocking the call. These are my code scraps.

<script  language="javascript" type="text/javascript">
        function ConfirmFuncn() {
            var Msge = document.getElementById('<%=hdnMsge.ClientID %>').value;
            if (confirm(Msge)) {
                document.getElementById('<%=hdnTestValue.ClientID %>').value = "true";
            }
            else {
                document.getElementById('<%=hdnTestValue.ClientID %>').value = "false";
            }

            document.getElementById('<%=btnSaveHidden.ClientID %>').Click();
        }
    </script>

<asp:Button ID="btnSaveHidden" runat="server" Visible="false" 
                            Text="HiddenSaveButton" onclick="btnSaveHidden_Click"
                             />

Here it does not call btnSaveHidden_Click . Javascript function ConfirmFuncn is calling properly, because i am getting the message value I set to hidden field. But btnSaveHidden_Click is not triggering. Why?

it wont work when:

Visible="False"

incited of hidden the button by it self just hide in indies a hidden div :

you can hide your button with hidden div

<div style="display: none;">    
    <asp:Button ID="btnSaveHidden" runat="server" Visible="false" 
                Text="HiddenSaveButton" onclick="btnSaveHidden_Click" />
</div>

Use style="display: none;" instead of Visible="false"

<asp:Button ID="btnSaveHidden" runat="server" style="display: none;"     
            Text="HiddenSaveButton" onclick="btnSaveHidden_Click" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM