This is a migrated thread and some comments may be shown as answers.

Problem with Button vs. RadButton

1 Answer 116 Views
Button
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 11 Jun 2012, 01:07 PM

I have an ASP.net button and I set the CssClass to something so that I can use Jquery to select it and force the click event when someone hits the enter key and this works the way I want it to.  The problem is that I am using Telerik skins so when I assign the cssclass the styling on the button goes away.  If I change the button to a RadButton the styling remains even if I set the CssClass to something however my Jquery selector obviously won't work anymore.

I have to select by class because I won't know the client id of the button because of edit form templates, master page, other containers, etc...

So how can I either:

a.) Select the RadButton using Jquery similar to the example below? Or,
b.) Style the ASP.net button using telerik skins while still assigning a CSSClass so that I can still use this below?


$(document).keypress(function (event) {
  if (event.keyCode == 13) {
    event.preventDefault();
    $(".submit-button").click();
  } else {
    return true;
  }
});

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Jun 2012, 04:28 AM
Hi Robert,

Here is the code snippet I tried to achieve your scenario.

ASPX:
<telerik:RadButton ID="RadButton1" runat="server" Text="Button" Skin="Hay" CssClass="a">
</telerik:RadButton>

CSS:
<style type="text/css">
  .class
    {
        background-color:Red;
    }
</style>

JS:
<script type="text/javascript">
    $(document).ready(function (event) {
        $(document).keypress(function (event) {
            alert("xfgg");
            if (event.keyCode == 13) {
                event.preventDefault();
                $(".class").click();
            } else {
                return true;
            }
        });
        $(".class").click(function () {
        alert("Handler for .click() called.");
    })
});
</script>

Please provide your full code if it doesn't help.

Thanks,
Princy.
Tags
Button
Asked by
Robert
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or