Brian
asked on
UserControls
Hi,
I created two UserControls called CalvertGrade1 and CalvertGrade2. I have code that populates the data into a GridView control for each UserControl.
I have my main page called index.aspx which Registers both UserControls on the index page. However when i run the index.aspx page i receive an error saying that TextBox1 is not declared. TextBox1 is on the index.aspx page and have it on both UserControls.
I can supply code if needed.
Please help!!
I created two UserControls called CalvertGrade1 and CalvertGrade2. I have code that populates the data into a GridView control for each UserControl.
I have my main page called index.aspx which Registers both UserControls on the index page. However when i run the index.aspx page i receive an error saying that TextBox1 is not declared. TextBox1 is on the index.aspx page and have it on both UserControls.
I can supply code if needed.
Please help!!
Code needed....
ASKER
INDEX.ASPX:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql Client" %>
<%@ Import Namespace="System.Data.Sql Types" %>
<%@ Import Namespace="System.Configur ation" %>
<%@ Import Namespace="System.Web.UI.W ebControls " %>
<%@ Import Namespace="System.Web.UI.W ebControls .WebParts. WebPart" %>
<%@ Register Src="~/CalvertGrade1.ascx" TagName="CalvertGrade1" TagPrefix="uc1"%>
<%@ Register Src="~/CalvertGrade2.ascx" TagName="CalvertGrade2" TagPrefix="uc2" %>
<!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 id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form2" runat="server">
<asp:WebPartManager ID="WebPartManager1" runat="server" />
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextB ox>
<asp:Button ID="Button1" runat="server" Text="Find Data" />
<br />
<br />
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<uc1:CalvertGrade1 ID="GridView1" runat="server"></uc1:Calve rtGrade1>
</ZoneTemplate>
</asp:WebPartZone>
<br />
<br />
<asp:WebPartZone ID="WebPartZone2" runat="server">
<ZoneTemplate>
<uc2:CalvertGrade2 ID="GridView2" runat="server"></uc2:Calve rtGrade2>
</ZoneTemplate>
</asp:WebPartZone>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Configur
<%@ Import Namespace="System.Web.UI.W
<%@ Import Namespace="System.Web.UI.W
<%@ Register Src="~/CalvertGrade1.ascx"
<%@ Register Src="~/CalvertGrade2.ascx"
<!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 id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form2" runat="server">
<asp:WebPartManager ID="WebPartManager1" runat="server" />
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextB
<asp:Button ID="Button1" runat="server" Text="Find Data" />
<br />
<br />
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<uc1:CalvertGrade1 ID="GridView1" runat="server"></uc1:Calve
</ZoneTemplate>
</asp:WebPartZone>
<br />
<br />
<asp:WebPartZone ID="WebPartZone2" runat="server">
<ZoneTemplate>
<uc2:CalvertGrade2 ID="GridView2" runat="server"></uc2:Calve
</ZoneTemplate>
</asp:WebPartZone>
</div>
</form>
</body>
</html>
ASKER
CALVERTGRADE1.ASCX:
<%@ Control Language="VB" ClassName="CalvertGrade1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql Client" %>
<%@ Import Namespace="System.Data.Sql Types" %>
<%@ Import Namespace="System.Configur ation" %>
<%@ Import Namespace="System.Web.UI.W ebControls " %>
<%@ Import Namespace="System.Web.UI.W ebControls .WebParts. WebPart" %>
Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim connectionString As String = ConfigurationManager.Conne ctionStrin gs("PSSA") .Connectio nString
Dim conn As SqlConnection = New SqlConnection(connectionSt ring)
Dim dtGrade1 As DataTable = New DataTable()
Dim gradeComm As SqlCommand
gradeComm = New SqlCommand("WebPart1Test", conn)
gradeComm.CommandType = CommandType.StoredProcedur e
' Create Parameter for Querystring
gradeComm.Parameters.Add(" @stid", SqlDbType.Int)
gradeComm.Parameters("@sti d").Value = Request("TextBox1.Text")
Dim adapter As SqlDataAdapter
Try
conn.Open()
adapter = New SqlDataAdapter
adapter.SelectCommand = gradeComm
adapter.Fill(dtGrade1)
GridView1.DataSource = dtGrade1
GridView1.DataBind()
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="STID" HeaderText="Student ID" />
<asp:BoundField DataField="STFNAME" HeaderText="First Name" />
<asp:BoundField DataField="STLNAME" HeaderText="Last Name" />
<asp:BoundField DataField="CALVONEID" HeaderText="Calvert 1st Grade ID" />
</Columns>
</asp:GridView>
<%@ Control Language="VB" ClassName="CalvertGrade1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Configur
<%@ Import Namespace="System.Web.UI.W
<%@ Import Namespace="System.Web.UI.W
Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim connectionString As String = ConfigurationManager.Conne
Dim conn As SqlConnection = New SqlConnection(connectionSt
Dim dtGrade1 As DataTable = New DataTable()
Dim gradeComm As SqlCommand
gradeComm = New SqlCommand("WebPart1Test",
gradeComm.CommandType = CommandType.StoredProcedur
' Create Parameter for Querystring
gradeComm.Parameters.Add("
gradeComm.Parameters("@sti
Dim adapter As SqlDataAdapter
Try
conn.Open()
adapter = New SqlDataAdapter
adapter.SelectCommand = gradeComm
adapter.Fill(dtGrade1)
GridView1.DataSource = dtGrade1
GridView1.DataBind()
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="STID" HeaderText="Student ID" />
<asp:BoundField DataField="STFNAME" HeaderText="First Name" />
<asp:BoundField DataField="STLNAME" HeaderText="Last Name" />
<asp:BoundField DataField="CALVONEID" HeaderText="Calvert 1st Grade ID" />
</Columns>
</asp:GridView>
ASKER
CALVERTGRADE2.ASCX:
<%@ Control Language="VB" ClassName="CalvertGrade1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql Client" %>
<%@ Import Namespace="System.Data.Sql Types" %>
<%@ Import Namespace="System.Configur ation" %>
<%@ Import Namespace="System.Web.UI.W ebControls " %>
<%@ Import Namespace="System.Web.UI.W ebControls .WebParts. WebPart" %>
Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim connectionString As String = ConfigurationManager.Conne ctionStrin gs("PSSA") .Connectio nString
Dim conn As SqlConnection = New SqlConnection(connectionSt ring)
Dim dtGrade2 As DataTable = New DataTable()
Dim grade1Comm As SqlCommand
grade1Comm = New SqlCommand("WebPart2Test", conn)
grade1Comm.CommandType = CommandType.StoredProcedur e
' Create Parameter for Querystring
grade1Comm.Parameters.Add( "@stid", SqlDbType.Int)
grade1Comm.Parameters("@st id").Value = Request("TextBox1.Text")
Dim adapter As SqlDataAdapter
Try
conn.Open()
adapter = New SqlDataAdapter
adapter.SelectCommand = grade1Comm
adapter.Fill(dtGrade2)
GridView2.DataSource = dtGrade2
GridView2.DataBind()
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
<asp:GridView ID="GridView2" runat="server">
<Columns>
<asp:BoundField DataField="STID" HeaderText="Student ID" />
<asp:BoundField DataField="STFNAME" HeaderText="First Name" />
<asp:BoundField DataField="STLNAME" HeaderText="Last Name" />
<asp:BoundField DataField="CALVTWOID" HeaderText="Calvert 2nd Grade ID" />
</Columns>
</asp:GridView>
<%@ Control Language="VB" ClassName="CalvertGrade1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Configur
<%@ Import Namespace="System.Web.UI.W
<%@ Import Namespace="System.Web.UI.W
Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim connectionString As String = ConfigurationManager.Conne
Dim conn As SqlConnection = New SqlConnection(connectionSt
Dim dtGrade2 As DataTable = New DataTable()
Dim grade1Comm As SqlCommand
grade1Comm = New SqlCommand("WebPart2Test",
grade1Comm.CommandType = CommandType.StoredProcedur
' Create Parameter for Querystring
grade1Comm.Parameters.Add(
grade1Comm.Parameters("@st
Dim adapter As SqlDataAdapter
Try
conn.Open()
adapter = New SqlDataAdapter
adapter.SelectCommand = grade1Comm
adapter.Fill(dtGrade2)
GridView2.DataSource = dtGrade2
GridView2.DataBind()
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
<asp:GridView ID="GridView2" runat="server">
<Columns>
<asp:BoundField DataField="STID" HeaderText="Student ID" />
<asp:BoundField DataField="STFNAME" HeaderText="First Name" />
<asp:BoundField DataField="STLNAME" HeaderText="Last Name" />
<asp:BoundField DataField="CALVTWOID" HeaderText="Calvert 2nd Grade ID" />
</Columns>
</asp:GridView>
ASKER
crazyman,
Please note that i added as you will see on my UserControls Request("TextBox1.Text") and now i do not receive that error. HOWEVER, when i run my index.aspx page i have a button that needs to retrieve data from both UserControls through the ButtonClick Event on index.aspx but when i just run the page i receive the error message below.
'Button1_Click' is not a member of 'ASP.index_aspx'.
Please note that i added as you will see on my UserControls Request("TextBox1.Text") and now i do not receive that error. HOWEVER, when i run my index.aspx page i have a button that needs to retrieve data from both UserControls through the ButtonClick Event on index.aspx but when i just run the page i receive the error message below.
'Button1_Click' is not a member of 'ASP.index_aspx'.
This wont work
Request("TextBox1.Text")
However you could do
(this.Page.FindControl("Te xtBox1") as TextBox).Text
Request("TextBox1.Text")
However you could do
(this.Page.FindControl("Te
Now i see.
You cannot have the Button1_Click events from the page fire the user control
Create a method on your user controls
public sub DoWork(text as string)
....#
then in your click on the page call
GridView2.DoWork(me.TextBo x1.Text)
You cannot have the Button1_Click events from the page fire the user control
Create a method on your user controls
public sub DoWork(text as string)
....#
then in your click on the page call
GridView2.DoWork(me.TextBo
ASKER
crazyman,
Ok, no ERRORS which is good but no DATA either :(
I think it has something to do with the following below and my lack of knowledge on how to use what you supplied.
' Create Parameter for Querystring
gradeComm.Parameters.Add(" @stid", SqlDbType.Int)
gradeComm.Parameters("@sti d").Value = Me.Page.FindControl("TextB ox1") as TextBox).Text
i receive a message at --> as TextBox).Text that says End of Statement Expected. Not sure what i need to do here.
Ok, no ERRORS which is good but no DATA either :(
I think it has something to do with the following below and my lack of knowledge on how to use what you supplied.
' Create Parameter for Querystring
gradeComm.Parameters.Add("
gradeComm.Parameters("@sti
i receive a message at --> as TextBox).Text that says End of Statement Expected. Not sure what i need to do here.
ASKER
Also how do i declare the GridView controls on the Button Click Event on index.aspx?
Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
--> GridView1.DoWork1(Me.TextB ox1.Text)
--> GridView2.DoWork2(Me.TextB ox1.Text)
End Sub
Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
--> GridView1.DoWork1(Me.TextB
--> GridView2.DoWork2(Me.TextB
End Sub
ASKER
Hi crazyman,
Are you still able to help with this?
Are you still able to help with this?
Okay
change this
gradeComm.Parameters("@sti d").Value = Me.Page.FindControl("TextB ox1") as TextBox).Text
to
gradeComm.Parameters("@sti d").Value = text;
NB text is the name of your function param
change this
gradeComm.Parameters("@sti
to
gradeComm.Parameters("@sti
NB text is the name of your function param
ASKER
Ok a few questions:
1.) I'm passing in an Integer value not String will this matter?
2.) When i did run everything after adding gradeComm.Parameters("@sti d").Value = text; i got an error saying that i need to Declare GridView1 and GridView2 on the ButtonClick Event.
1.) I'm passing in an Integer value not String will this matter?
2.) When i did run everything after adding gradeComm.Parameters("@sti
1.Okay the integer value is fine provding your stored proc expects it.
2.You would need to do a FindControl to get the user control instances, this should be something along the lines of
CalvertGrade1 GridView1= this.WebPartZone1.FindCont rol("GridV iew1") as CalvertGrade1
CalvertGrade2 GridView2= this.WebPartZone1.FindCont rol("GridV iew2") as CalvertGrade2
2.You would need to do a FindControl to get the user control instances, this should be something along the lines of
CalvertGrade1 GridView1= this.WebPartZone1.FindCont
CalvertGrade2 GridView2= this.WebPartZone1.FindCont
ASKER
crazyman,
I want you know that i have posted questions like this before and you will be my HERO if i get this to work since othes where unable to :)
You are correct with the Integer.
I added the last step below and do not receive any errors when running but when i run it now i don't get and data :( I'm pretty i have to do something with the functions that i created in my UserControl pages Public Sub DoWork1() but not sure how to tie this in to the following below.
WebPartGrade1 = Me.WebPartZone1.FindContro l("GridVie w1")
WebPartGrade2 = Me.WebPartZone2.FindContro l("GridVie w2")
I want you know that i have posted questions like this before and you will be my HERO if i get this to work since othes where unable to :)
You are correct with the Integer.
I added the last step below and do not receive any errors when running but when i run it now i don't get and data :( I'm pretty i have to do something with the functions that i created in my UserControl pages Public Sub DoWork1() but not sure how to tie this in to the following below.
WebPartGrade1 = Me.WebPartZone1.FindContro
WebPartGrade2 = Me.WebPartZone2.FindContro
okay, providing you have AutoEventWireUp set to true, this in your index page should work...
Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
CalvertGrade1 GridView1= this.WebPartZone1.FindControl("GridView1") as CalvertGrade1
CalvertGrade2 GridView2= this.WebPartZone1.FindControl("GridView2") as CalvertGrade2
GridView1.DoWork(cint(me.TextBox1.Text))
GridView2DoWork(cint(me.TextBox1.Text))
end sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Arggghhh, vb.net is not my forte
change the this for Me
change the this for Me
ASKER
It's okay i figured that i needed to change "this" to "Me".
Okay, i added all the code to my ButtonClick Event Handler and no errors/messages are appearing within the code, BUT when i run the page i receive the following error message below.
Object reference not set to an instance of an object.
this message appears on the same line as --> GridView1.DoWork1(CInt(Me. TextBox1.T ext))
Okay, i added all the code to my ButtonClick Event Handler and no errors/messages are appearing within the code, BUT when i run the page i receive the following error message below.
Object reference not set to an instance of an object.
this message appears on the same line as --> GridView1.DoWork1(CInt(Me.
at a guess it could not find the GridView controls
first of change the second lline to look at WebPartZone2 not 1
then step through and hover over GridView1, is it null ?
first of change the second lline to look at WebPartZone2 not 1
then step through and hover over GridView1, is it null ?
ASKER
>> first of change the second lline to look at WebPartZone2 not 1
I did change that back.
I'm using an ID that i used before and will work with both UserControls. I'm not sure what you mean by step through and hover over GridView1, to see if it's null.
would this be a problem see below with the word Text?
gradeComm.Parameters.Add(" @stid", SqlDbType.Int)
gradeComm.Parameters("@sti d").Value = Text <------------
I did change that back.
I'm using an ID that i used before and will work with both UserControls. I'm not sure what you mean by step through and hover over GridView1, to see if it's null.
would this be a problem see below with the word Text?
gradeComm.Parameters.Add("
gradeComm.Parameters("@sti
ASKER
crazyman,
I also tried to Step over in Debug but that didn't work either i still get the same error message
Object reference not set to an instance of an object.
I also tried to Step over in Debug but that didn't work either i still get the same error message
Object reference not set to an instance of an object.
can you report your code and i will take a look.
ASKER
INDEX.ASPX PAGE:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql Client" %>
<%@ Import Namespace="System.Data.Sql Types" %>
<%@ Import Namespace="System.Configur ation" %>
<%@ Import Namespace="System.Web.UI.W ebControls " %>
<%@ Import Namespace="System.Web.UI.W ebControls .WebParts. WebPart" %>
<%@ Register Src="~/CalvertGrade1.ascx" TagName="CalvertGrade1" TagPrefix="uc1" %>
<%@ Register Src="~/CalvertGrade2.ascx" TagName="CalvertGrade2" TagPrefix="uc2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
WebPartManager1.DisplayMod e = WebPartManager.DesignDispl ayMode
End Sub
Public Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim GridView1 As CalvertGrade1 = DirectCast(Me.WebPartZone1 .FindContr ol("GridVi ew1"), CalvertGrade1)
Dim GridView2 As CalvertGrade2 = DirectCast(Me.WebPartZone2 .FindContr ol("GridVi ew2"), CalvertGrade2)
GridView1.DoWork1(CInt(Me. TextBox1.T ext))
GridView2.DoWork2(CInt(Me. TextBox1.T ext))
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form2" runat="server">
<asp:WebPartManager ID="WebPartManager1" runat="server" />
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextB ox>
<asp:Button ID="Button1" runat="server" Text="Find Data" OnClick="Button1_Click" />
<br />
<br />
<asp:WebPartZone ID="WebPartZone1" runat="server" BorderColor="#CCCCCC" Font-Names="Verdana" Padding="6">
<EmptyZoneTextStyle Font-Size="0.8em" />
<PartStyle Font-Size="0.8em" ForeColor="#333333" />
<TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="White" />
<MenuLabelHoverStyle ForeColor="Yellow" />
<MenuPopupStyle BackColor="#1C5E55" BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.6em" />
<MenuVerbStyle BorderColor="#1C5E55" BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
<PartTitleStyle BackColor="#1C5E55" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
<ZoneTemplate>
<uc1:CalvertGrade1 ID="WebPartGrade1" runat="server"></uc1:Calve rtGrade1>
</ZoneTemplate>
<MenuVerbHoverStyle BackColor="#E3EAEB" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" ForeColor="#333333" />
<PartChromeStyle BackColor="#E3EAEB" BorderColor="#C5BBAF" Font-Names="Verdana" ForeColor="#333333" />
<HeaderStyle Font-Size="0.7em" ForeColor="#CCCCCC" HorizontalAlign="Center" />
<MenuLabelStyle ForeColor="#333333" />
</asp:WebPartZone>
<br />
<br />
<asp:WebPartZone ID="WebPartZone2" runat="server" BorderColor="#CCCCCC" Font-Names="Verdana" Padding="6">
<EmptyZoneTextStyle Font-Size="0.8em" />
<PartStyle Font-Size="0.8em" ForeColor="#333333" />
<TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="White" />
<MenuLabelHoverStyle ForeColor="#E2DED6" />
<MenuPopupStyle BackColor="#5D7B9D" BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.6em" />
<MenuVerbStyle BorderColor="#5D7B9D" BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
<PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
<ZoneTemplate>
<uc2:CalvertGrade2 ID="WebPartGrade2" runat="server"></uc2:Calve rtGrade2>
</ZoneTemplate>
<MenuVerbHoverStyle BackColor="#F7F6F3" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" ForeColor="#333333" />
<PartChromeStyle BackColor="#F7F6F3" BorderColor="#E2DED6" Font-Names="Verdana" ForeColor="White" />
<HeaderStyle Font-Size="0.7em" ForeColor="#CCCCCC" HorizontalAlign="Center" />
<MenuLabelStyle ForeColor="White" />
</asp:WebPartZone>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Configur
<%@ Import Namespace="System.Web.UI.W
<%@ Import Namespace="System.Web.UI.W
<%@ Register Src="~/CalvertGrade1.ascx"
<%@ Register Src="~/CalvertGrade2.ascx"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
WebPartManager1.DisplayMod
End Sub
Public Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim GridView1 As CalvertGrade1 = DirectCast(Me.WebPartZone1
Dim GridView2 As CalvertGrade2 = DirectCast(Me.WebPartZone2
GridView1.DoWork1(CInt(Me.
GridView2.DoWork2(CInt(Me.
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form2" runat="server">
<asp:WebPartManager ID="WebPartManager1" runat="server" />
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextB
<asp:Button ID="Button1" runat="server" Text="Find Data" OnClick="Button1_Click" />
<br />
<br />
<asp:WebPartZone ID="WebPartZone1" runat="server" BorderColor="#CCCCCC" Font-Names="Verdana" Padding="6">
<EmptyZoneTextStyle Font-Size="0.8em" />
<PartStyle Font-Size="0.8em" ForeColor="#333333" />
<TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="White" />
<MenuLabelHoverStyle ForeColor="Yellow" />
<MenuPopupStyle BackColor="#1C5E55" BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.6em" />
<MenuVerbStyle BorderColor="#1C5E55" BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
<PartTitleStyle BackColor="#1C5E55" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
<ZoneTemplate>
<uc1:CalvertGrade1 ID="WebPartGrade1" runat="server"></uc1:Calve
</ZoneTemplate>
<MenuVerbHoverStyle BackColor="#E3EAEB" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" ForeColor="#333333" />
<PartChromeStyle BackColor="#E3EAEB" BorderColor="#C5BBAF" Font-Names="Verdana" ForeColor="#333333" />
<HeaderStyle Font-Size="0.7em" ForeColor="#CCCCCC" HorizontalAlign="Center" />
<MenuLabelStyle ForeColor="#333333" />
</asp:WebPartZone>
<br />
<br />
<asp:WebPartZone ID="WebPartZone2" runat="server" BorderColor="#CCCCCC" Font-Names="Verdana" Padding="6">
<EmptyZoneTextStyle Font-Size="0.8em" />
<PartStyle Font-Size="0.8em" ForeColor="#333333" />
<TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="White" />
<MenuLabelHoverStyle ForeColor="#E2DED6" />
<MenuPopupStyle BackColor="#5D7B9D" BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.6em" />
<MenuVerbStyle BorderColor="#5D7B9D" BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
<PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
<ZoneTemplate>
<uc2:CalvertGrade2 ID="WebPartGrade2" runat="server"></uc2:Calve
</ZoneTemplate>
<MenuVerbHoverStyle BackColor="#F7F6F3" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" ForeColor="#333333" />
<PartChromeStyle BackColor="#F7F6F3" BorderColor="#E2DED6" Font-Names="Verdana" ForeColor="White" />
<HeaderStyle Font-Size="0.7em" ForeColor="#CCCCCC" HorizontalAlign="Center" />
<MenuLabelStyle ForeColor="White" />
</asp:WebPartZone>
</div>
</form>
</body>
</html>
ASKER
CALVERTGRADE1.ASCX PAGE:
<%@ Control Language="VB" ClassName="CalvertGrade1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql Client" %>
<%@ Import Namespace="System.Data.Sql Types" %>
<%@ Import Namespace="System.Configur ation" %>
<%@ Import Namespace="System.Web.UI.W ebControls " %>
<%@ Import Namespace="System.Web.UI.W ebControls .WebParts. WebPart" %>
<script runat="server">
Public Sub DoWork1(ByVal Text As Integer)
Dim connectionString As String = ConfigurationManager.Conne ctionStrin gs("PSSA") .Connectio nString
Dim conn As SqlConnection = New SqlConnection(connectionSt ring)
Dim dtGrade1 As DataTable = New DataTable()
Dim gradeComm As SqlCommand
gradeComm = New SqlCommand("WebPart1Test", conn)
gradeComm.CommandType = CommandType.StoredProcedur e
' Create Parameter for Querystring
gradeComm.Parameters.Add(" @stid", SqlDbType.Int)
gradeComm.Parameters("@sti d").Value = Text
Dim adapter As SqlDataAdapter
Try
conn.Open()
adapter = New SqlDataAdapter
adapter.SelectCommand = gradeComm
adapter.Fill(dtGrade1)
GridView1.DataSource = dtGrade1
GridView1.DataBind()
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
</script>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false ">
<Columns>
<asp:BoundField DataField="STID" HeaderText="Student ID" />
<asp:BoundField DataField="STFNAME" HeaderText="First Name" />
<asp:BoundField DataField="STLNAME" HeaderText="Last Name" />
<asp:BoundField DataField="CALVONEID" HeaderText="Calvert 1st Grade ID" />
</Columns>
</asp:GridView>
<%@ Control Language="VB" ClassName="CalvertGrade1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Configur
<%@ Import Namespace="System.Web.UI.W
<%@ Import Namespace="System.Web.UI.W
<script runat="server">
Public Sub DoWork1(ByVal Text As Integer)
Dim connectionString As String = ConfigurationManager.Conne
Dim conn As SqlConnection = New SqlConnection(connectionSt
Dim dtGrade1 As DataTable = New DataTable()
Dim gradeComm As SqlCommand
gradeComm = New SqlCommand("WebPart1Test",
gradeComm.CommandType = CommandType.StoredProcedur
' Create Parameter for Querystring
gradeComm.Parameters.Add("
gradeComm.Parameters("@sti
Dim adapter As SqlDataAdapter
Try
conn.Open()
adapter = New SqlDataAdapter
adapter.SelectCommand = gradeComm
adapter.Fill(dtGrade1)
GridView1.DataSource = dtGrade1
GridView1.DataBind()
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
</script>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false
<Columns>
<asp:BoundField DataField="STID" HeaderText="Student ID" />
<asp:BoundField DataField="STFNAME" HeaderText="First Name" />
<asp:BoundField DataField="STLNAME" HeaderText="Last Name" />
<asp:BoundField DataField="CALVONEID" HeaderText="Calvert 1st Grade ID" />
</Columns>
</asp:GridView>
ASKER
CALVERTGRADE2.ASCX PAGE:
<%@ Control Language="VB" ClassName="CalvertGrade2" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql Client" %>
<%@ Import Namespace="System.Data.Sql Types" %>
<%@ Import Namespace="System.Configur ation" %>
<%@ Import Namespace="System.Web.UI.W ebControls " %>
<%@ Import Namespace="System.Web.UI.W ebControls .WebParts. WebPart" %>
<script runat="server">
Public Sub DoWork2(ByVal Text As Integer)
Dim connectionString As String = ConfigurationManager.Conne ctionStrin gs("PSSA") .Connectio nString
Dim conn As SqlConnection = New SqlConnection(connectionSt ring)
Dim dtGrade2 As DataTable = New DataTable()
Dim grade1Comm As SqlCommand
grade1Comm = New SqlCommand("WebPart2Test", conn)
grade1Comm.CommandType = CommandType.StoredProcedur e
' Create Parameter for Querystring
grade1Comm.Parameters.Add( "@stid", SqlDbType.Int)
grade1Comm.Parameters("@st id").Value = Text
Dim adapter As SqlDataAdapter
Try
conn.Open()
adapter = New SqlDataAdapter
adapter.SelectCommand = grade1Comm
adapter.Fill(dtGrade2)
GridView2.DataSource = dtGrade2
GridView2.DataBind()
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
</script>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false ">
<Columns>
<asp:BoundField DataField="STID" HeaderText="Student ID" />
<asp:BoundField DataField="STFNAME" HeaderText="First Name" />
<asp:BoundField DataField="STLNAME" HeaderText="Last Name" />
<asp:BoundField DataField="CALVTWOID" HeaderText="Calvert 2nd Grade ID" />
</Columns>
</asp:GridView>
<%@ Control Language="VB" ClassName="CalvertGrade2" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Configur
<%@ Import Namespace="System.Web.UI.W
<%@ Import Namespace="System.Web.UI.W
<script runat="server">
Public Sub DoWork2(ByVal Text As Integer)
Dim connectionString As String = ConfigurationManager.Conne
Dim conn As SqlConnection = New SqlConnection(connectionSt
Dim dtGrade2 As DataTable = New DataTable()
Dim grade1Comm As SqlCommand
grade1Comm = New SqlCommand("WebPart2Test",
grade1Comm.CommandType = CommandType.StoredProcedur
' Create Parameter for Querystring
grade1Comm.Parameters.Add(
grade1Comm.Parameters("@st
Dim adapter As SqlDataAdapter
Try
conn.Open()
adapter = New SqlDataAdapter
adapter.SelectCommand = grade1Comm
adapter.Fill(dtGrade2)
GridView2.DataSource = dtGrade2
GridView2.DataBind()
Catch ex As Exception
Finally
conn.Close()
End Try
End Sub
</script>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false
<Columns>
<asp:BoundField DataField="STID" HeaderText="Student ID" />
<asp:BoundField DataField="STFNAME" HeaderText="First Name" />
<asp:BoundField DataField="STLNAME" HeaderText="Last Name" />
<asp:BoundField DataField="CALVTWOID" HeaderText="Calvert 2nd Grade ID" />
</Columns>
</asp:GridView>
change
Dim GridView1 As CalvertGrade1 = DirectCast(Me.WebPartZone1 .FindContr ol("WebPar tGrade1"), CalvertGrade1)
Dim GridView2 As CalvertGrade2 = DirectCast(Me.WebPartZone2 .FindContr ol("WebPar tGrade2"), CalvertGrade2)
Dim GridView1 As CalvertGrade1 = DirectCast(Me.WebPartZone1
Dim GridView2 As CalvertGrade2 = DirectCast(Me.WebPartZone2
ASKER
I recieve the following error message below.
Error message: Object reference not set to an instance of an object.
The error is on the line below.
GridView1.DoWork1(CInt(Me. TextBox1.T ext))
Error message: Object reference not set to an instance of an object.
The error is on the line below.
GridView1.DoWork1(CInt(Me.
ASKER
Hi crazyman,
I also tried different settings for what you provided in 22740248 but it still goes to GridView1.DoWork1(CInt(Me. TextBox1.T ext)) for the error.
I also tried different settings for what you provided in 22740248 but it still goes to GridView1.DoWork1(CInt(Me.
ASKER
Please let me know if you are still able to help with this post. Thank you!
ASKER
Hi crazyman i found someone else to help me finish this post since i didn't hear back from you. So i figured i would show you what was needed. See below.
Public Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim WebPartGrade1 As WebPart = WebPartManager1.WebParts(" WebPartGra de1")
Dim WebPartGrade2 As WebPart = WebPartManager1.WebParts(" WebPartGra de2")
Dim GridView1 As CalvertGrade1 = DirectCast(WebPartGrade1.C ontrols(0) , CalvertGrade1)
Dim GridView2 As CalvertGrade2 = DirectCast(WebPartGrade2.C ontrols(0) , CalvertGrade2)
If Me.TextBox1.Text = "" Then
TextBox1.Text = ""
Else
GridView1.DoWork1(CInt(Me. TextBox1.T ext))
GridView2.DoWork2(CInt(Me. TextBox1.T ext))
End If
Public Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim WebPartGrade1 As WebPart = WebPartManager1.WebParts("
Dim WebPartGrade2 As WebPart = WebPartManager1.WebParts("
Dim GridView1 As CalvertGrade1 = DirectCast(WebPartGrade1.C
Dim GridView2 As CalvertGrade2 = DirectCast(WebPartGrade2.C
If Me.TextBox1.Text = "" Then
TextBox1.Text = ""
Else
GridView1.DoWork1(CInt(Me.
GridView2.DoWork2(CInt(Me.
End If