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

onclientclick and onclick for bt on radajaxpanel

3 Answers 396 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Rann
Top achievements
Rank 1
Rann asked on 18 Jun 2014, 02:29 PM
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?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Jun 2014, 02:53 PM
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.
0
Rann
Top achievements
Rank 1
answered on 18 Jun 2014, 07:42 PM
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>



0
Viktor Tachev
Telerik team
answered on 23 Jun 2014, 11:26 AM
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.

 
Tags
Ajax
Asked by
Rann
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rann
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or