Webgrid in a WebTab causes Microsoft JScript runtime error: 'null' is null or not an object error.

1 reply. Last post: November 29, 2010 12:50 PM by Handy Surya
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Jason WrightMember

I have a web grid inside a Webtab.  The webgrid's datasource changes depending on a button click (different tables for each button).

 

This works beautifully when sitting in a page by itself, however the minute I place it in a WebTab, I get problems whenever I click on a control that does a post back (the error being Microsoft JScript runtime error: 'null' is null or not an object).

Here is the aspx page.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Master.aspx.vb" Inherits="SCLSalesOrderForm.Master" %>

<%@ Register Assembly="ISNet.WebUI.WebDesktop" Namespace="ISNet.WebUI.WebDesktop"
    TagPrefix="ISWebDesktop" %>
<%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %>
<html>
<head id="Head1" runat="server">
    <title>Master Page</title>
    <link rel="stylesheet" type="text/css" href="../global.css" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="-1" />
    <meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
</head>
<body id="Body1" runat="server">
    <form id="Form1" runat="server" style="height: 552px">
    <div>
        <ISWebDesktop:WebTab ID="WebTab1" runat="server" Height="600px" Width="800px">
            <TabPages>
                <ISWebDesktop:WebTabItem Text="Tab 1">
                    <PageTemplate>
                        <div>
                            <br />
                            <asp:Table ID="Table2" runat="server">
                                <asp:TableRow>
                                    <asp:TableCell>
                                        <asp:Button ID="btnCustomer" runat="server" Text="Customer Lookup" />
                                    </asp:TableCell>
                                    <asp:TableCell>
                                        <asp:Button ID="btnSales" runat="server" Text="Sales Order Lookup" />
                                    </asp:TableCell>
                                    <asp:TableCell>
                                        <asp:Button ID="btnProcess" runat="server" Text="Process Sales Order" />
                                    </asp:TableCell>
                                </asp:TableRow>
                            </asp:Table>
                            <br />
                            <ISWebGrid:WebGrid ID="grdWebGrid1" runat="server" Height="500px" UseDefaultStyle="true"
                                DefaultStyleMode="Win7" HorizontalAlign="NotSet" OnInitializeRow="grdWebGrid1_InitializeRow"
                                OnInitializeDataSource="grdWebGrid1_InitializeDataSource" OnPrepareDataBinding="grdWebGrid1_PrepareDataBinding"
                                Width="790px">
                                <FlyPostBackSettings PostInputControls="True" />
                                <RootTable DataKeyField="" GridLineStyle="NotSet" Caption="Valuations">
                                </RootTable>
                                <LayoutSettings AllowAddNew="No" AllowDelete="No" AllowColumnMove="Yes" AllowEdit="No"
                                    AllowExport="Yes" AllowFilter="Yes" AllowGrouping="Yes" AllowSelectColumns="Yes"
                                    AllowSorting="Yes">
                                </LayoutSettings>
                            </ISWebGrid:WebGrid>
                        </div>
                    </PageTemplate>
                </ISWebDesktop:WebTabItem>
                <ISWebDesktop:WebTabItem Text="Tab 2">
                    <PageTemplate>
                        <div>
                            Test Tab 2
                        </div>
                    </PageTemplate>
                </ISWebDesktop:WebTabItem>
                <ISWebDesktop:WebTabItem Text="Tab 3">
                    <PageTemplate>
                        <div>
                            Test Tab 3
                        </div>
                    </PageTemplate>
                </ISWebDesktop:WebTabItem>
            </TabPages>
        </ISWebDesktop:WebTab>
        <asp:HiddenField ID="fldMode" runat="server" />
    </div>
    </form>
</body>
</html>

 

And here is the backend code.

BackEnd Code:

Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Management
Imports System.Web
Partial Public Class Master
    Inherits System.Web.UI.Page
    Dim mw As New MessageWindow

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            fldMode.Value = "Customer"
        End If

        WebTab1.ActiveTabIndex = Convert.ToInt16(fldTab.Value)

        grdWebGrid1.RebindDataSource()

    End Sub
    Protected Sub grdWebGrid1_InitializeDataSource(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.DataSourceEventArgs)

        Dim ds As New DataSet
        Dim DBConn As SqlConnection
        Dim da As SqlDataAdapter
        Dim DBSelect As String

        If fldMode.Value = "Customer" Then
            DBSelect = "Select [Customer], [Name], [CreditStatus] as 'Credit Status', [ShipToAddr3] as 'Suburb', [ShipToAddr4] as 'State', [Salesperson], [Contact] from [ArCustomer] ORDER BY [Customer] ASC"
            DBConn = New SqlConnection(ConfigurationManager.ConnectionStrings("SCL").ConnectionString)
            da = New SqlDataAdapter(DBSelect, DBConn)
            da.Fill(ds, "Customer")
            grdWebGrid1.RootTable.DataKeyField = "Customer"
        Else
            DBSelect = "Select [SalesOrder] as 'Sales Order', [OrderStatus] as 'Order Status', [Customer], [Salesperson], [CustomerPoNumber] as 'PO Number', [OrderDate] as 'Order Date' from [SorMaster] where ActiveFlag <> 'N'"
            DBConn = New SqlConnection(ConfigurationManager.ConnectionStrings("SCL").ConnectionString)
            da = New SqlDataAdapter(DBSelect, DBConn)
            da.Fill(ds, "SalesOrder")
            grdWebGrid1.RootTable.DataKeyField = "SalesOrder"
        End If

        e.DataSource = ds

    End Sub

    Protected Sub grdWebGrid1_PrepareDataBinding(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.DataSourceEventArgs)

        grdWebGrid1.RetrieveHierarchicalStructure()

    End Sub
    Protected Sub grdWebGrid1_InitializeRow(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.RowEventArgs) Handles grdWebGrid1.InitializeRow

        If grdWebGrid1.RootTable.DataKeyField = "SalesOrder" Then
            grdWebGrid1.RootTable.Columns.GetNamedItem("Order Date").DataFormatString = "dd/MM/yyyy"
        End If

    End Sub


    Private Sub btnSales_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSales.Click

        fldMode.Value = "SalesOrder"
        Dim ds As New DataSet
        Dim DBConn As SqlConnection
        Dim da As SqlDataAdapter
        Dim DBSelect As String

        DBSelect = "Select [SalesOrder] as 'Sales Order', [OrderStatus] as 'Order Status', [Customer], [Salesperson], [CustomerPoNumber] as 'PO Number', [OrderDate] as 'Order Date' from [SorMaster] where ActiveFlag <> 'N'"
        DBConn = New SqlConnection(ConfigurationManager.ConnectionStrings("SCL").ConnectionString)
        da = New SqlDataAdapter(DBSelect, DBConn)
        da.Fill(ds, "SalesOrder")
        grdWebGrid1.RootTable.DataKeyField = "SalesOrder"
        grdWebGrid1.Width = 650
        grdWebGrid1.DataSource = ds
        grdWebGrid1.RebindDataSource()

    End Sub

    Private Sub btnCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCustomer.Click

        Dim ds As New DataSet
        Dim DBConn As SqlConnection
        Dim da As SqlDataAdapter
        Dim DBSelect As String

        fldMode.Value = "Customer"
        DBSelect = "Select [Customer], [Name], [CreditStatus] as 'Credit Status', [ShipToAddr3] as 'Suburb', [ShipToAddr4] as 'State', [Salesperson], [Contact] from [ArCustomer] ORDER BY [Customer] ASC"
        DBConn = New SqlConnection(ConfigurationManager.ConnectionStrings("SCL").ConnectionString)
        da = New SqlDataAdapter(DBSelect, DBConn)
        da.Fill(ds, "Customer")
        grdWebGrid1.RootTable.DataKeyField = "Customer"
        grdWebGrid1.Width = 790

        grdWebGrid1.DataSource = ds
        grdWebGrid1.RebindDataSource()

    End Sub

    Private Sub btnProcess_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProcess.Click

        Try
            Dim ThisKey As String
            Dim ThisRow As Integer
            Dim ThisMode As String

            ThisRow = grdWebGrid1.RetrieveClientLastSelectedObject().RowIndex
            ThisKey = Convert.ToString(grdWebGrid1.RootTable.Rows(ThisRow).Cells(0).Value)

            If ThisKey = "" Then
                Call mw.UserMsgBox("Please select an instruction to process.")
            Else
                If fldMode.Value = "Customer" Then
                    ThisMode = "Add"
                Else
                    ThisMode = "Update"
                End If

                Dim StringURL As String = "SorDetail.aspx?Mode=" & ThisMode & "&id=" & ThisKey
                Page.Response.Redirect(StringURL)
            End If
        Catch ex As Exception
            If fldMode.Value = "Customer" Then
                Call mw.UserMsgBox("Please select a customer to process.")
            Else
                Call mw.UserMsgBox("Please select a sales order to process.")
            End If

        End Try

    End Sub
End Class

If I initially click on the other tabs, I get the correct information displayed - the only problem seems to occur when I click on one of the  buttons that sends a postback.

 

The version of WebDesktopManager is 3.0.7200.310 and the version of WebGrid is 7.0.7200.403.

 

Thanks,

 

Jason.

 

 

All times are GMT -5. The time now is 11:16 PM.
Previous Next