onclientclick and onclick for bt on radajaxpanel

4 posts, 0 answers
  1. Rann
    Rann avatar
    2 posts
    Member since:
    Jun 2014

    Posted 18 Jun 2014 Link to this post

    I am brand new to the world of coding web pages and have a question. 

    I have a table on a RadAjaxPanel. The first column is description labels and a couple of the labels have a button to pop detail.  The remaining columns are actually the data we are editing and are a RadListView.  When the user clicks on a detail button, we pop a modal window, do some data entry, recalculate and then update and save the information that is being displayed/edited in the RadListView.  This all works great unless the user has edited data in the RadListView and then pops the detail before saving the data.  If that happens, the detail gets saved, the data being displayed in the RadListView gets reloaded, tweaked and saved basically throwing away any changes the user made and did not save. 

    To try and get around this, I added an OnClientClick call to a javascript function that would  fire the onclick of the forms "save" button and return true so that the detail modal form would fire up based on the onclick event.  Well, the onclientclick fires, but then the onclick never does.  If it matters, I set the onclientclick event statically and set the onclick dynamically during the page load so I can pass the correct guid as a parameter to the detail modal form. I did this based on info I found that said OnClientClick fires before the OnClick event and the OnClick event fires or not based on the return value of the OnClientClick event.

    Any thoughts/comments?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Jun 2014 in reply to Rann Link to this post

    Hi Rann,

    The problem is that returning any boolean value (regardless of true/false) is causing the post-back to be cancelled. In this scenario "returning true" though it seems intuitive - doesn't behave as expected. Please change your code as shown in the following sample.

    ASPX:
    <asp:Button ID="btnSubmit" runat="server" OnClientClick="if (!MyFunction()) return false;" />

    JavaScript:
    <script type="text/javascript">
        function MyFunction() {
            if (somecondition) {
                return true;
            }
            else {
                return false;
            }
        }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rann
    Rann avatar
    2 posts
    Member since:
    Jun 2014

    Posted 18 Jun 2014 in reply to Princy Link to this post

    Thanks for the help Princy!  That got me part way there.  The data in the ListView saves and then the modal detail window starts to pop up, but doesn't stay.  I see a white space appear and as quick as it appears it closes.  Is there something I need to reset between the javescript calls?  I did put breakpoints in the .cs file and it is calling the page_load and initialize functions for the detail window.

    <telerik:RadCodeBlock runat="server">
    <script type="text/javascript">

    function SaveDataBeforePopDetail() {
    var o = document.getElementById('<%=btnSave.ClientID%>');
    o.click();
    return true;
    }

    function ShowAddEditOverheadExpenses(RentPlanGuid) {
    var oWnd = window.radopen("Dialogs/OverheadExpenses.aspx?RentPlanGuid=" + RentPlanGuid, "rwOverheadExpenses");
     return false;
    }
    </telerik:RadCodeBlock>



  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 23 Jun 2014 Link to this post

    Hi Rann,

    If you would like to pass some information to the RadWindow and open it from the server you could use an approach similar to the one described in the following article.

    Opening RadWindow from the server

    Let me know how this approach works for you.

    Regards,
    Viktor Tachev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top