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.PageProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With New TestDb().bind(Me.form1)
End WithEnd 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.SqlClientPublic Class TestDb
Public Sub New()
End SubPublic Sub bind(ByVal FormData As Web.UI.HtmlControls.HtmlForm)
Dim Parameter As Object
If FormData IsNot Nothing ThenDim 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 SubPublic Function GetGrid(ByVal Control As Web.UI.Control) As Web.UI.Control
Dim c As Web.UI.ControlFor 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
NextReturn c
End FunctionPublic Function GetTextBox(ByVal Control As Web.UI.Control) As Web.UI.Control
Dim c As Web.UI.ControlFor 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
NextReturn c
End FunctionPublic 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!!!!!