I wrote this function in javascript
function CheckBeforeAddNew(btnId, gridSelected) {
$(btnId).click(function () {
for (var i in gridSelected) {
return true;
};
Ext.Msg.alert('Add', 'Can not do without selected item');
{
return false;
};
});
};
and when I trying to make this function arrive on button click like this:
<ext:Button runat="server" ID="btnAddNewToMme" Cls="topButton" Text="Add new" Icon="Add" OnDirectClick="btnAddNewToMme_OnDirectClick">
<DirectEvents>
<Click Before="CheckBeforeAddNew('#<%= btnAddNewToMme.ClientID%>','<%=dlOuterObject.Grid_ClientID %>.selectedIds')"></Click>
</DirectEvents>
</ext:Button>
I got error ReferenceError: $ is not defined
$(btnId).click(function () {
How can I invoke this function to make this work?
Edit:
Of course I added file with this function to my .aspx like
<script type="text/javascript" src="Scripts/Synchronization.js"></script>
Edit1:
in firebug i can see before anything else
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
so jQuery is loaded correctly
Edit2:
I’ve made changes in my function which @geoffrey provide:
var CheckBeforeAddNew = function (gridSelected) {
for (var i in gridSelected) {
return true;
}
Ext.Msg.alert('Error', 'Something wrong!');
return false;
};
But using of it
<ext:Button runat="server" ID="btnAddNewToMme" Cls="topButton" Text="Add new" Icon="Add" OnDirectClick="btnAddNewToMme_OnDirectClick">
<DirectEvents>
<Click Before="return CheckBeforeAddNew('<%= dlOuterObject.Grid_ClientID %>.selectedIds');"></Click>
</DirectEvents>
</ext:Button>
I can’t make this work:
if (grid.getSelectionModel().getCount() < 1) {
Ext.Msg.alert('Error', 'Please select an Item');
return false;
}
my dlOuterObject is UserControl which contains grid. So any ideas how make it work?
Thanks for any help:)
There are a few issues with your original code samples.
This
<%= btnAddNewToMme.ClientID%>syntax does not work in ASP.NET markup configuration. You would need to use<%# %>DataBinding syntax.Your
CheckBeforeAddNewJavaScript function does not use thebtnId, so you shouldn’t need to pass this.You don’t need to use any jQuery either. All the functionality required is included in the
ExtJSframework, which is already included on yourPage.Just pass an instance of the
GridPanelinto your JavaScript function, then encapsulate your logic for getting/checking the Selected Item count in the function.Here’s a fully functional sample demonstrating the scenario using Ext.NET 2.0. If you’re using v1.x, the code
.Beforehandler is basically the same, just the GridPanel Model config would be slightly different.Example
Hope this helps.