0

I have a javascript function which I want to send a ASP button control. So my function is like this:

<script type="text/javascript">
    function PreventKeyPress(e, sender, button) {
        //do something with the button
        button.click();
    }
</script>

From the ASP markup I want to be able to pass the button in. I've tried a few ways but this is something like I'd want to do:

<asp:TextBox ID="textBoxDate" runat="server" onKeyDown="PreventKeyPress(event, this, <%=buttonDate.ClientId %>);" />
<asp:ImageButton ID="buttonDate" runat="server" />

Any ideas how I can get this to work?

0

1 Answer 1

1

.aspx page

<form id="form1" runat="server">
<asp:TextBox ID="textBoxDate" runat="server" onKeyDown="PreventKeyPress(event, this, 'buttonDate');" />
<asp:ImageButton ID="buttonDate" runat="server" onclick="buttonDate_Click" />
</form>
<script type="text/javascript">
    function PreventKeyPress(e, sender, button) {
        console.log(e + '.......' + sender + '.......' + button);
        var buttonObj = document.getElementById(button);
        buttonObj.click();
    }
</script>

This worked on my system... Hope this helps...!!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.