Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8525157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:53:40+00:00 2026-06-11T07:53:40+00:00

I wrote this function in javascript function CheckBeforeAddNew(btnId, gridSelected) { $(btnId).click(function () { for

  • 0

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:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:53:41+00:00Added an answer on June 11, 2026 at 7:53 am

    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 CheckBeforeAddNew JavaScript function does not use the btnId, 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 ExtJS framework, which is already included on your Page.

    Just pass an instance of the GridPanel into 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 .Before handler is basically the same, just the GridPanel Model config would be slightly different.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                var store = this.GridPanel1.GetStore();
    
                store.DataSource = this.Data;
                store.DataBind();
            }
        }
    
        private object[] Data
        {
            get
            {
                return new object[]
                {
                    new object[] { "3m Co" },
                    new object[] { "Alcoa Inc" },
                    new object[] { "Altria Group Inc" },
                    new object[] { "American Express Company" },
                    new object[] { "American International Group, Inc." },
                    new object[] { "AT&T Inc." },
                    new object[] { "Boeing Co." },
                    new object[] { "Caterpillar Inc." },
                    new object[] { "Citigroup, Inc." },
                    new object[] { "E.I. du Pont de Nemours and Company" },
                    new object[] { "Exxon Mobil Corp" },
                    new object[] { "General Electric Company" }
                };
            }
        }
    
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            X.Msg.Notify("Message", "Button1 Clicked").Show();
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Simple Array Grid - Ext.NET Examples</title>
    
        <script type="text/javascript">
            var checkSelected = function (grid) {
                if (grid.getSelectionModel().getCount() < 1) {
                    Ext.Msg.alert('Error', 'Please select an Item');
    
                    return false;
                }
    
                return true;
            };
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:GridPanel 
            ID="GridPanel1"
            runat="server" 
            Title="Example" 
            Width="600" 
            Height="350">
            <Store>
                <ext:Store runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="company" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel>
                <Columns>
                    <ext:Column runat="server" Text="Company" DataIndex="company" Flex="1" />
                </Columns>            
            </ColumnModel>       
            <SelectionModel>
                <ext:RowSelectionModel runat="server" Mode="Multi" />
            </SelectionModel>
            <Buttons>
                <ext:Button runat="server" Text="Submit" Icon="Accept">
                    <DirectEvents>
                        <Click OnEvent="Button1_Click" Before="return checkSelected(App.GridPanel1);" />
                    </DirectEvents>
                </ext:Button>
            </Buttons>
        </ext:GridPanel>
    </body>
    </html>
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this javascript Function : function ShowMsg(msg) { $.blockUI({ message: '<div dir=rtl align=center><h1><p>'
I wrote this code but it doesn't work: JavaScript: $(function() { var menu_h_number=5 for
I wrote this code in javascript: String.prototype = { a : function() { alert('a');
I wrote this on a simple ASP.NET page: jQuery(document).ready(function() { jQuery(form).submit(function() { alert(kikoo); return
I wrote the following class in javascript function main() { this.area ; this.$= function(target)
I wrote a class in javascript that looks like this: function main() { this.var1
I don't know much about Javascript, and this function I wrote doesn't seem to
how to call javascript function from vbscript. i wrote like this <script type=text/vbscript> jsfunction()
today i wrote this function: function zoom(obj){ var img = (!document.getElementById(obj))?false:document.getElementById(obj); var fullImage =
I wrote this snippet of javascript/jQuery to change a check box. http://jsfiddle.net/johnhoffman/crF93/ Javascript $(function()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.