The grid gets binded to a datatable but the page returns a javascript error.

Last post 03-17-2008 1:29 AM by Spanco. 3 replies.

Sort Posts:

  • The grid gets binded to a datatable but the page returns a javascript error.

    03-13-2008, 6:07 PM
    • Loading...
    • juvalencia
    • Joined on 02-06-2007, 7:46 AM
    • Posts 3

    Hi i am trying to use an update panel and through a class so i don't have to put the connection code in the page, the class works fine but the grid in the shows up and javascript error shows up. I don't now what to do?

     This the aspx page (Default.aspx):

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

    <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

    Namespace="System.Web.UI" TagPrefix="asp" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Untitled Page</title>

    </head>

    <body>

    <form id="form1" runat="server">

    <asp:ScriptManager ID="smTest" runat="server">

    </asp:ScriptManager>

    <table style="width: 328px">

    <tr>

    <td style="width: 92px">

    Product Class</td>

    <td style="width: 158px">

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>

    <td style="width: 69px">

    <asp:Button ID="btRefresh" runat="server" Text="Refresh" UseSubmitBehavior="False" /></td>

    </tr>

    <tr>

    <td colspan="3" rowspan="2">

    <asp:UpdatePanel ID="upTest" runat="server" RenderMode="Inline">

    <ContentTemplate>

    <asp:GridView ID="gvProducts" runat="server">

    </asp:GridView>

    </ContentTemplate>

    <Triggers>

    <asp:AsyncPostBackTrigger ControlID="btRefresh" EventName="Click" />

    </Triggers>

    </asp:UpdatePanel>

    </td>

    </tr>

    <tr>

    </tr>

    </table>

    </form>

    </body>

    </html>

     This the code in the Page.Load()

    Partial Class _Default

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    With New TestDb()

    .bind(Me.form1)

    End With

    End Sub

    End Class

    And the class that has the Bind method is

     

    Imports Microsoft.VisualBasic

    Imports System.Web.UI.WebControls

    Imports System.Web.UI

    Imports System.Data

    Imports System.Data.SqlClient

    Public Class TestDb

    Public Sub New()

    End Sub

    Public Sub bind(ByVal FormData As Web.UI.HtmlControls.HtmlForm)

    Dim Parameter As Object

    If FormData IsNot Nothing Then

    Dim control As Web.UI.Control

    control = Me.GetGrid(FormData)

    Parameter = CType(Me.GetTextBox(FormData), TextBox).Text

    CType(control, Web.UI.WebControls.GridView).DataSource = Me.SetDataSource(Parameter)

    CType(control, Web.UI.WebControls.GridView).DataBind()

    End If

    End Sub

    Public Function GetGrid(ByVal Control As Web.UI.Control) As Web.UI.Control

    Dim c As Web.UI.Control

    For Each c In Control.Controls

    If c.Controls.Count >= 1 Then

    c = GetGrid(c.Controls(0))

    End If

    If TypeOf c Is System.Web.UI.WebControls.GridView Then

    Exit For

    End If

    Next

    Return c

    End Function

    Public Function GetTextBox(ByVal Control As Web.UI.Control) As Web.UI.Control

    Dim c As Web.UI.Control

    For Each c In Control.Controls

    If c.Controls.Count >= 1 Then

    c = GetGrid(c.Controls(0))

    ElseIf TypeOf c Is System.Web.UI.WebControls.TextBox Then

    Exit For

    End If

    Next

    Return c

    End Function

    Public Function SetDataSource(ByVal Parameter As Object) As Data.DataTable

    Dim ds As New DataSet()

    Dim cn As New SqlConnection("Server=(local);Database=AdventureWorks;User ID=sa;Password=******;Trusted_Connection=False;")

    Dim cm As New SqlCommand("select pro.ProductId,pro.Name,pro.Color,pro.Class,pro.ProductModelId from Production.Product as pro with (nolock) where @p0 is null or (pro.ProductModelId = @p0)", cn)

    Dim p0 As New SqlParameter("@p0", Parameter)

    cm.Parameters.Add(p0)

    Dim da As New SqlDataAdapter(cm)

    da.Fill(ds)

    Return ds.Tables(0)

    End Function

    End Class

     

    The error message is:

     

     

    Line: 41

    Char: 1

    Error: ‘Sys’ is undefined

    Code: 0

    URL: http://localhost:49164/AjaxTesting/

     

    Line: 75

    Char: 1

    Error: ‘Sys’ is undefined

    Code: 0

    URL: http://localhost:49164/AjaxTesting/

    PLEASE HELP!!!!!

  • Re: The grid gets binded to a datatable but the page returns a javascript error.

    03-14-2008, 3:21 AM
    Answer
    • Loading...
    • Spanco
    • Joined on 06-11-2007, 1:51 AM
    • New Delhi, India
    • Posts 317

     Hi there is a huge post listing in the forum ,pleae search before posting

    the answer is ,the web.config should contain the two line

    There are two key tags, that must exist on web.config:

     under <assemblies> (possibly you already have this one)
    <add assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

    under <httpHandlers> (this is the new one)
    <add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>

     

     

    please mark as answer if the post helps u . 

     

    Nothing is impossible as the IMPOSSIBLE word itself says I M Possible...just you have to try..u get all what you desire

    BLOG ::--> http://dotnetarmy.blogspot.com/
    URL ::--> http://www.asp.net
  • Re: The grid gets binded to a datatable but the page returns a javascript error.

    03-14-2008, 4:28 PM
    • Loading...
    • juvalencia
    • Joined on 02-06-2007, 7:46 AM
    • Posts 3

    Hi,

    Not, the answer didn't help me because my web.config has those two lines.

     

     

  • Re: The grid gets binded to a datatable but the page returns a javascript error.

    03-17-2008, 1:29 AM
    • Loading...
    • Spanco
    • Joined on 06-11-2007, 1:51 AM
    • New Delhi, India
    • Posts 317

     OOPs My self is wrong ,sorry friend ,I will help u out .in the mean while u should visit the some post .

    http://forums.asp.net/p/1040236/1878829.aspx#1878829

    http://forums.asp.net/p/1226719/2202981.aspx#2202981

    http://forums.asp.net/p/1134010/1805768.aspx#1805768

    http://forums.asp.net/p/1040236/1849344.aspx#1849344

    http://forums.asp.net/p/1040236/1488054.aspx#1488054

    http://forums.asp.net/p/1055400/1577578.aspx#1577578

     

     

    Nothing is impossible as the IMPOSSIBLE word itself says I M Possible...just you have to try..u get all what you desire

    BLOG ::--> http://dotnetarmy.blogspot.com/
    URL ::--> http://www.asp.net
Page 1 of 1 (4 items)
Microsoft Communities
Page view counter