Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
javascript code does not run!
what should I do

XML
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    test5

     <script type="text/javascript">

         function expandFirstRow(grid, row) {
             if (grid.$rows().index(row) == 0) {

                 grid.expandRow(row);
             }
         }

         function employees_onRowDataBound(e) {
             var grid = $(this).data('tGrid');
             expandFirstRow(grid, e.row);
         }

         function orders_onRowDataBound(e) {
             var grid = $(this).data('tGrid');
             expandFirstRow(grid, e.row);
         }
    </script>
</asp:Content>
Posted
Updated 25-Mar-13 3:53am
v2
Comments
ZurdoDev 25-Mar-13 9:54am    
You should call the JS function. It won't run automatically.
Sergey Alexandrovich Kryukov 25-Mar-13 11:34am    
Do you want to confuse poor OP even further? Of course, any JS function can be called from any other JS function. But what will perform the very first call?
—SA
Sergey Alexandrovich Kryukov 25-Mar-13 11:48am    
I actually answered, please see.
—SA
medloyl1 25-Mar-13 9:55am    
how should i call it PLZ !!!
Sergey Alexandrovich Kryukov 25-Mar-13 11:32am    
From anywhere you want. :-)
—SA

You are apparently asking your question too early. You should have first read at least the rudimentary JavaScript manual with some "Hello, word!" code samples.

Please see my comment to the question. All the calls to JavaScript code should be started from some point after the page is loaded. There are two distinct ways:

  1. If you place some script in the <body> element, it will be executed top to button.
  2. You can put any JavaScript code in any element's event handler, such as onclick, and a lot more. One important case is the onload event supported by a number of elements. It's special because it does not require any user input after the page is loaded. Please see:
    http://www.w3schools.com/jsref/event_onload.asp[^],
    http://www.w3schools.com/jsref/event_onclick.asp[^].

    You need to understand the syntax of HTML elements. Just for example:
    http://www.pageresource.com/jscript/jbutton.htm[^].

    In the help pages for each event you will also see the syntax used to add an event handler in the JavaScipt code itself.


This should give you the idea, but you hardly can learn is all from one short answer (especially if you did not learn it so far from documentation, which should be much easier). So the documentation and use some basic manuals.

Good luck,
—SA
 
Share this answer
 
thank you for ue response,i want to show my View Code to get an idea ,i see that all the steps are correct but i think that the JS bloc dont can not execute:



XML
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcApplication43.Models.MasterDetailViewModel>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    test5

     <script type="text/javascript">

         function expandFirstRow(grid, row) {
             if (grid.$rows().index(row) == 0) {

                 grid.expandRow(row);
             }
         }

         function employees_onRowDataBound(e) {
             var grid = $(this).data('tGrid');
             expandFirstRow(grid, e.row);
         }

         function orders_onRowDataBound(e) {
             var grid = $(this).data('tGrid');
             expandFirstRow(grid, e.row);
         }
    </script>
</asp:Content>



<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>test5</h2>

<%= Html.Telerik().Grid(Model)
        .Name("Employees")
        .Columns(columns =>
        {
            columns.Bound(e => e.Lot_Number).Width(140);
            columns.Bound(e => e.Item_Number).Width(140);
            columns.Bound(e => e.QC_Approval).Width(140);
            columns.Bound(e => e.QCDateApproval).Width(140);
            columns.Bound(e => e.QCUser).Width(140);
            columns.Bound(e => e.QA_Release).Width(140);
            columns.Bound(e => e.QADateRelease).Width(140);
            columns.Bound(e => e.QAUser).Width(140);

        })
        .ClientEvents(events => events.OnRowDataBound("employees_onRowDataBound"))
        .DetailView(details => details.ClientTemplate(
                Html.Telerik().Grid(Model)
                        .Name("Orders_<#= Lot_Number #>")
                    .Columns(columns =>
                    {
                         columns.Bound(o => o.ResultDefinition_ID).Visible(false).Width(101);
                        columns.Bound(o => o.ResultDefinition_Nr).Width(101);
                        columns.Bound(o => o.ResultName).Width(101);
                        columns.Bound(o => o.LIMSName).Width(101);
                        columns.Bound(o => o.Unit).Width(101);
                        columns.Bound(o => o.LowLimit).Width(101);
                         columns.Bound(o => o.HighLimit).Width(101);

                    })

                    .ClientEvents(events => events.OnRowDataBound("orders_onRowDataBound"))
                    .DetailView(ordersDetailView => ordersDetailView.ClientTemplate(

                        Html.Telerik().Grid(Model)
                            .Name("OrderDetails_<#= ResultDefinition_ID #>")
                            .Columns(columns =>
                            {

                                columns.Bound(od => od.Result_Num).Width(200);
                                columns.Bound(od => od.Result_Text).Width(200);

                            })
                            .DataBinding(dataBinding => dataBinding.Ajax()
                                 .Select("_OrderDetailsForOrderHierarchyAjax", "Home", new {
                                     ResultDefinition_ID = "<#= ResultDefinition_ID #>" }))
                            .Pageable()
                            .Sortable()
                            .ToHtmlString()
                     ))
                    .DataBinding(dataBinding => dataBinding.Ajax()
                        .Select("_OrdersForEmployeeHierarchyAjax", "Home", new { Lot_Number =
                            "<#= Lot_Number #>" }))
                    .Pageable()
                    .Sortable()
                    .Filterable()
                    .ToHtmlString()
        ))
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_EmployeesHierarchyAjax", "Home"))
        .Pageable(paging => paging.PageSize(5))
        .Scrollable(scrolling => scrolling.Height(580))
        .Sortable()
    %>



</asp:Content>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900