Radbutton not working but asp:button does

11 posts, 0 answers
  1. David Penny
    David Penny avatar
    174 posts
    Member since:
    Jun 2006

    Posted 10 Jun 2011 Link to this post

    Hi,

    I extensively use RadWindow to edit records from a dataset and this has all been working great. I recently switched from using asp:button to RadButton and my CloseWindow() code does not seem to work when called from RadButton.

    I have added both an asp:button and telerik:Radbutton to a page as below:
    <asp:Button ID="Button1" runat="server" Text="Cancel"
        Width="100px" OnClientClick="CloseWindow();" />
    <telerik:RadButton ID="btnCancel" runat="server" Text="Cancel"
        Width="100px" OnClientClicked="CloseWindow();" CausesValidation="false"></telerik:RadButton>

    The asp:button correctly closes the window, but the RadButton does not. Am I doing something wrong here?

    When I click on the button I get the following message from explorer:

    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; FDM)
    Timestamp: Fri, 10 Jun 2011 11:13:14 UTC

    Message: Expected '}'
    Line: 639
    Char: 262
    Code: 0
    URI: http://localhost:1580/P5Time/(S(1jnywutrtzbw552lk2ry5mgd))/EditEvent.aspx?Mode=Insert&Start=2011-06-07+09%3a30&IsAllDay=false&duration=15&rwndrnd=0.9248140078625935

    And the source indicated is shown below:
    Sys.Application.add_init(function() {
        $create(Telerik.Web.UI.RadButton, {"_postBackReference":"","clientStateFieldID":"btnAddFavourite_ClientState","iconData":{},"imageData":{},"text":"Add Favourite","toggleStatesData":[],"uniqueGroupName":"","uniqueID":"btnAddFavourite","width":"100px"}, null, null, $get("btnAddFavourite"));
    });
    Sys.Application.add_init(function() {
        $create(Telerik.Web.UI.RadButton, {"_postBackReference":"","clientStateFieldID":"btnSave_ClientState","iconData":{},"imageData":{},"text":"Save","toggleStatesData":[],"uniqueGroupName":"","uniqueID":"btnSave","width":"100px"}, null, null, $get("btnSave"));
    });
    Sys.Application.add_init(function() {
        $create(Telerik.Web.UI.RadButton, {"_postBackReference":"","clientStateFieldID":"btnExport_ClientState","iconData":{},"imageData":{},"text":"Export","toggleStatesData":[],"uniqueGroupName":"","uniqueID":"btnExport","width":"100px"}, null, null, $get("btnExport"));
    });
    Sys.Application.add_init(function() {
        $create(Telerik.Web.UI.RadButton, {"_postBackReference":"","clientStateFieldID":"btnSaveAndClose_ClientState","iconData":{},"imageData":{},"text":"Save + Close","toggleStatesData":[],"uniqueGroupName":"","uniqueID":"btnSaveAndClose","width":"100px"}, null, null, $get("btnSaveAndClose"));
    });
    Sys.Application.add_init(function() {
        $create(Telerik.Web.UI.RadButton, {"_postBackReference":"","clientStateFieldID":"btnDelete_ClientState","iconData":{},"imageData":{},"text":"Delete","toggleStatesData":[],"uniqueGroupName":"","uniqueID":"btnDelete","width":"100px"}, null, null, $get("btnDelete"));
    });
    Sys.Application.add_init(function() {
        $create(Telerik.Web.UI.RadButton, {"_postBackReference":"","clientStateFieldID":"btnCancel_ClientState","iconData":{},"imageData":{},"text":"Cancel","toggleStatesData":[],"uniqueGroupName":"","uniqueID":"btnCancel","width":"100px"}, {"clicked":CloseWindow();}, null, $get("btnCancel"));
    });

    The error seems to indicate an issue around the btnDelete definition but it looks the same as all the others. Other RadButtons on the same page appear to work correctly, but they all call server code whereas this Cancel button only calls a javascript function.

    David Penny


  2. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 10 Jun 2011 Link to this post

    Hi David Penny,

    The problem comes from the way you specified the event handler for OnClientClicked event - what you need to do is to set the name of the handler function without brackets and semicolon.

    Here you can see the correct code to setup your RadButton:
    <telerik:RadButton ID="btnCancel" runat="server" Text="Cancel"
        Width="100px" OnClientClicked="CloseWindow" CausesValidation="false"></telerik:RadButton>

    The article provided below should also help you:
    http://www.telerik.com/help/aspnet-ajax/button-onclientclicked.html

    Regards,
    Slav
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. David Penny
    David Penny avatar
    174 posts
    Member since:
    Jun 2006

    Posted 13 Jun 2011 Link to this post

    Slav,

    Thanks for the reply, but it still does it if I change as suggested. However, I'll have to look at my page definition, because this works fine on other pages so there must be some problem higher up somewhere.

    David Penny
  5. David Penny
    David Penny avatar
    174 posts
    Member since:
    Jun 2006

    Posted 13 Jun 2011 Link to this post

    Slav,

    OK - my fault. This works OK now. However, one other problem has cropped up.

    I have an asp:button which calls a RadWindow() - asp:button works OK, but I cannot get RadButton to work without problems because the javascript call needs to return false to prevent the RadWindow closing immediately.

    The following works:
    <asp:button="btnCharges" runat="server" Text="Charges" Width="100px"  OnClientClick="return ShowCharges()"/>

    But when translated to RadButton does not:
    <telerik:RadButton ID="btnCharges" runat="server" Text="Charges" Width="100px" CausesValidation="false" OnClientClicked="return ShowCharges()"/>

    Not sure of the exact syntax required here. Have tried return ShowCharges() and return ShowCharges();

    Both give errors.

    ShowCharges works OK, but immediately closes the RadWindow again.

    David Penny
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Jun 2011 Link to this post

    Hello David,

    This is the expected behavior. Since RadButton is a postBack control, you need to cancel the postback. One suggestion is to set the AutoPostBack property of RadButton to false.

    Here is a sample code.
    aspx:
    <telerik:RadButton ID="RadBtn1" runat="server" Text="OpenRadWindow" OnClientClicked="OnClientClicked" AutoPostBack="false">
    </telerik:RadButton>
    Javascript:
    function OnClientClicked()
    {
          radopen("http://www.google.com", null);
    }

    Thanks,
    Shinu.
  7. David Penny
    David Penny avatar
    174 posts
    Member since:
    Jun 2006

    Posted 13 Jun 2011 Link to this post

    Thanks Shinu, that fixed it.

    David Penny
  8. MTC
    MTC avatar
    26 posts
    Member since:
    Jan 2013

    Posted 13 Feb 2013 Link to this post

    Hi
    I have a simple requirement to create a record in Data Base. for this i have some fields on my webpage after filling that fields user can create a record.
    for this i am using RadAjaxPanel,RadScriptBlock,Rad Button,RadAjaxManager and RadAjaxLoadingPanel.
    the flow for creating r record would be:
    -> On button click first i want to call a JavaScript for validation( not asp validation) it returns true for successful validation else false..
    ->if it is true loading panel should appear on the screen and server side code should run.
    -> if it is false then loading panel should not appear JavaScript error message should display..

    Please help....




  9. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 14 Feb 2013 Link to this post

    Hi Shweta,

    You can use the following approach to achieve the desired functionality:
    1. Use the client-side event OnClientClicking of RadButton to check if your custom validation is fulfilled and to cancel the click event of the button if your form is not valid as shown in this online demo. The handler of this event can be used for displaying an error message if validation is not passed.
    2. If your form is validated, use the server-side Click event of the button to execute your logic on the code-behind.
    3. The RadAjaxLoadingPanel can be attached to a RadAjax control by setting its ID to the properties DefaultLoadingPanelID for a RadAjaxManager and LoadingPanelID for a RadAjaxPanel or RadAjaxManager UpdatedControl setting. You can check the online demos for examples with such a setup.

    Kind regards,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  10. MTC
    MTC avatar
    26 posts
    Member since:
    Jan 2013

    Posted 22 Feb 2013 Link to this post

    Hi
    can i call selectedindexchanged event on PreRender and asp button click event of telerik grid?
    if yes? can u please provide me sample code for that.
    i am using advance data binding.
  11. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Feb 2013 Link to this post

    Hi,

    You can use FireCommand to invoke Selectedindexchanged event. Here is the sample code.
    C#:
    protected void Button2_Click(object sender, EventArgs e)
       {
         RadGrid grid = (this.FindControl("RadGrid1") as RadGrid);
        (grid.MasterTableView.GetItems(GridItemType.Item)[0] as GridDataItem).FireCommandEvent(RadGrid.SelectCommandName, string.Empty);
       }

    Thanks,
    Shinu
  12. MTC
    MTC avatar
    26 posts
    Member since:
    Jan 2013

    Posted 22 Feb 2013 Link to this post

    Thanks i will try and let you know........
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017