 |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
 | This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

April 26th, 2010, 02:32 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 14 Button click event
Hi, I programmed a click event for a Button on my page. The problem is I am getting the "WithEvents" error either way I go. The error is "withEvents..." is required or it has already been declared. I am having the same problem with my DetailsView(s). They have not been declared or they are already declared.
Code:
Partial Class _Default
Inherits System.Web.UI.Page
Public DetailsViewCal, DetailsViewIsu As DetailsView
'Protected WithEvents Button1 As Button
Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If DetailsViewCal.Visible = "true" Then
DetailsViewCal.Visible = False
DetailsViewIsu.Visible = True
Button1.Text = "Back"
Else
DetailsViewCal.Visible = "False"
DetailsViewCal.Visible = True
DetailsViewIsu.Visible = False
Button1.Text = "Enter an Issue"
End If
End Sub
End Class
Error messags below:
BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
BC30260: 'DetailsViewCal' is already declared as 'Protected WithEvents DetailsViewCal As System.Web.UI.WebControls.DetailsView' in this class.
Source Error:
Line 1: Partial Class _Default
Line 2: Inherits System.Web.UI.Page
Line 3: Public DetailsViewCal, DetailsViewIsu As DetailsView
Line 4: 'Protected WithEvents Button1 As Button
I thought a control would be defined when I dropped it on the page. Default. vb.aspx doesn't seem to be aware of the data controls on my page. Thanks for your help.
|
|

April 26th, 2010, 02:40 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
To what exercise / page is this referring to?
Also, how does your markup look like and how many "code behind" files do you have?
Imar
|
|

April 26th, 2010, 03:17 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 14 Button click event
I wasn't referring to a specific exercise but rather to the concept
of programming events. I believe I have one code behind file since I have only
one sub procedure. When I open the code behind file it indicates "page" "load". Maybe this procedure should be somewhere else? Thanks.
|
|

April 26th, 2010, 03:51 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
I believe I have one code behind file since I have only one sub procedure.
|
Those concepts aren't related. With a Web Site Project you have one code behind file. With a Web Application Project you have two. The way controls are created in code differs between these two models. The number of sub procedures you add doesn't change the number of files.
Quote:
|
Also, how does your markup look like
|
Can you post your code?
It's probably a simple answer - comment out the line
Public DetailsViewCal, DetailsViewIsu As DetailsView
as these controls are already defined in the markup but I can't tell for sure if I don't know what that markup looks like.
Imar
|
|

April 26th, 2010, 04:07 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
chapter 14 button event
Thanks, that solved the problem on the page containing the
button and detailsViews. Now the other page I have generates
a "handle withEvents.." error referring to the button. The button
is on one page but a different page generates the error. Page generating
the "withEvents" error:
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" trace="false"%>
<%@ Register assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.DynamicData" tagprefix="cc1" %>
<!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>Glen's Web Site</title>
<style type="text/css">
.style2
{
font-weight: normal;
font-size: medium;
white-space: normal;
overflow: auto;
}
.style1
{
font-weight: normal;
font-family: "Arial Narrow";
font-size: medium;
text-decoration: underline;
white-space: normal;
overflow: scroll;
}
.style3
{
font-size: medium;
background-color: #CCFFCC;
white-space: normal;
overflow: auto;
font-family: "Arial Narrow";
font-weight: normal;
}
.style4
{
text-decoration: underline;
white-space: normal;
overflow: auto;
}
</style>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<link href="StyleSheet2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server" title="Contacts"
style="line-height: normal; vertical-align: inherit; text-align: left; background-color: #C0C0C0; position: relative; visibility: visible; display: block; overflow: visible; top: -2px; left: 17px; width: 570px; white-space: normal; height: 1097px;">
<h1 class="style3">
HCPF Contacts Page</h1>
<p style="height: 1px">
</p>
<h2 class="style2">
<span class="style1">Enter Client ID</span><span class="style4"> </span>
<asp:TextBox ID="TextBox1" runat="server" Width="100px" AutoPostBack="True"
BackColor="#FFCCFF" BorderStyle="Solid"
style="text-align: left; font-family: Arial; font-size: medium; background-color: #CCFFCC;"
Wrap="False"></asp:TextBox>
</h2>
<div>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:cstService2ConnectionString %>"
SelectCommand="SELECT [Dateofcontact], [Category], [userid], [Notes], [ClientID], [typekey], [Crezkey], [Csubkey], [kounty] FROM [tabContacts] WHERE ([ClientID] = @ClientID)">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="ClientID" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceRez" runat="server"
ConnectionString="<%$ ConnectionStrings:cstService2ConnectionString %>"
SelectCommand="SELECT [reskey], [rezolution] FROM [tabResolutions] ORDER BY [rezolution]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourcetyp" runat="server"
ConnectionString="<%$ ConnectionStrings:cstService2ConnectionString %>"
SelectCommand="SELECT [typekey], [Contact type] AS Contact_type FROM [tabTypes] ORDER BY [Contact type]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourcounty" runat="server"
ConnectionString="<%$ ConnectionStrings:cstService2ConnectionString %>"
SelectCommand="SELECT [c_id], [c_name] FROM [counties] ORDER BY [c_name]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceSub" runat="server"
ConnectionString="<%$ ConnectionStrings:cstService2ConnectionString %>"
SelectCommand="SELECT [subkey], [subjects] FROM [tabSubjects] ORDER BY [subjects]">
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateInsertButton="True" AutoGenerateRows="False" BackColor="#FFCCFF"
BorderColor="#663300" BorderStyle="Outset" Caption="Insert Contacts"
CaptionAlign="Left" DataSourceID="SqlDataSource4" DefaultMode="Insert"
Height="50px" Width="388px" InsertRowStyle-Wrap="true" CellSpacing="2"
style="font-family: 'Arial Narrow'">
<RowStyle Wrap="True" />
<FieldHeaderStyle BackColor="#99FF99" BorderStyle="Solid" />
<Fields>
<asp:BoundField DataField="Dateofcontact" HeaderText="Date of contact"
SortExpression="Dateofcontact" ApplyFormatInEditMode="True"
DataFormatString="{0:d}" />
<asp:BoundField DataField="ClientID" HeaderText="Client ID"
SortExpression="ClientID" NullDisplayText="Client ID is required" />
<asp:BoundField DataField="userid" HeaderText="User ID"
SortExpression="userid" />
<asp:BoundField DataField="Sortdate" HeaderText="Sortdate"
SortExpression="Sortdate" InsertVisible="False" DataFormatString="{0:d}" />
<asp:TemplateField HeaderText="How" SortExpression="typekey">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSourcetyp" DataTextField="Contact_type"
DataValueField="typekey" Width="200px" SelectedValue='<%# Bind("typekey") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSourcetyp" DataTextField="Contact_type"
DataValueField="typekey" Width="200px" SelectedValue='<%# Bind("typekey") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("typekey") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSourceSub" DataTextField="subjects"
DataValueField="subkey" Width="200px" SelectedValue='<%# Bind("subkey") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSourceSub" DataTextField="subjects"
DataValueField="subkey" Width="200px" SelectedValue='<%# Bind("subkey") %>'>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reason">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server"
DataSourceID="SqlDataSrceCats" DataTextField="Category_of_contact"
DataValueField="catkey" Width="200px" SelectedValue='<%# Bind("catkey") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server"
DataSourceID="SqlDataSrceCats" DataTextField="Category_of_contact"
DataValueField="catkey" Width="200px" SelectedValue='<%# Bind("catkey") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Csubkey") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Special" SortExpression="Crezkey">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSourceRez" DataTextField="rezolution"
DataValueField="reskey" SelectedValue='<%# Bind("reskey") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSourceRez" DataTextField="rezolution"
DataValueField="reskey" Width="200px" SelectedValue='<%# Bind("reskey") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Crezkey") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="County" SortExpression="kounty">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server"
DataSourceID="SqlDataSourcounty" DataTextField="c_name" DataValueField="c_id"
Width="200px">
</asp:DropDownList> </EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server"
DataSourceID="SqlDataSourcounty" DataTextField="c_name" DataValueField="c_id"
Width="200px">
</asp:DropDownList> </InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("kounty") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notes" SortExpression="Notes">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" TextMode="MultiLine" Wrap="true" Width="388" Height="50" runat="server" Text='<%# Bind("Notes") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" TextMode="MultiLine" Wrap="true" Width="388" Height="50" runat="server" Text='<%# Bind("Notes") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Notes" runat="server" Text='<%# Bind("Notes") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Height="200px" Width="200px" />
<HeaderStyle VerticalAlign="Top" />
<ItemStyle HorizontalAlign="Left" Width="200px" Wrap="True" />
</asp:TemplateField>
</Fields>
<InsertRowStyle Width="200px" Wrap="True" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSrceCats" runat="server"
ConnectionString="<%$ ConnectionStrings:cstService2ConnectionString %>"
SelectCommand="SELECT [catkey], [Category of contact] AS Category_of_contact FROM [tabCategories] ORDER BY [Category of contact]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourcGrid" runat="server"
ConnectionString="<%$ ConnectionStrings:cstService2ConnectionString %>"
SelectCommand="SELECT [Date of contact] AS Date_of_contact, [Category], [user id] AS user_id, [Notes], [ClientID], [Category of contact] AS Category_of_contact, [c_name], [rezolution], [Contact type] AS Contact_type, [subjects], [ContactKey] FROM [vwContaks] WHERE ([ClientID] = @ClientID) ORDER BY [Date of contact] DESC">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" DefaultValue="'t000008'"
Name="ClientID" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:cstService2ConnectionString %>"
InsertCommand="INSERT INTO tabContacts(Dateofcontact, userid, Notes, ClientID, Sortdate, typekey, Crezkey, Csubkey, kounty, Category) VALUES (@Dateofcontact, @userid, @Notes, @ClientID, @Sortdate, @typekey, @reskey, @subkey, @kounty, @catkey)"
SelectCommand="SELECT Dateofcontact, Category, userid, Notes, ClientID, Sortdate, typekey, Crezkey, Csubkey, kounty FROM tabContacts">
<InsertParameters>
<asp:Parameter Name="Dateofcontact" />
<asp:Parameter Name="userid" />
<asp:Parameter Name="Notes" />
<asp:Parameter Name="ClientID" />
<asp:Parameter Name="Sortdate" />
<asp:Parameter Name="kounty" />
<asp:ControlParameter ControlID="DetailsView1$DropDownList4" Name="Reason"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DetailsView1$DropDownList1" Name="How"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DetailsView1$DropDownList2" Name="Action"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DetailsView1$DropDownList3" Name="Special"
PropertyName="SelectedValue" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="ContactKey"
DataSourceID="SqlDataSourcGrid" PageSize="4">
<Columns>
<asp:BoundField DataField="Date_of_contact" HeaderText="Date"
SortExpression="Date_of_contact" ApplyFormatInEditMode="True"
DataFormatString="{0:d}" />
<asp:BoundField DataField="Notes" HeaderText="Notes"
SortExpression="Notes" ControlStyle-Width="100px" >
<ControlStyle Width="100px"></ControlStyle>
</asp:BoundField>
<asp:BoundField DataField="user_id" HeaderText="User ID"
SortExpression="user_id" />
<asp:BoundField DataField="Contact_type" HeaderText="How"
SortExpression="Contact_type" />
<asp:BoundField DataField="subjects" HeaderText="Action"
SortExpression="subjects" />
<asp:BoundField DataField="Category_of_contact" HeaderText="Reason"
SortExpression="Category_of_contact" />
<asp:BoundField DataField="rezolution" HeaderText="Special"
SortExpression="rezolution" />
<asp:BoundField DataField="c_name" HeaderText="County"
SortExpression="c_name" />
</Columns>
<HeaderStyle BackColor="#FFCCFF" />
<AlternatingRowStyle BackColor="#CCFFCC" />
</asp:GridView>
<br />
</form>
</body>
</html>
|
|

April 26th, 2010, 04:11 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Again difficult to say as you're not posting the complete picture (e.g. markup and code behind of the same page).
Could it be that the Inherits or CodeFile attributes of one page are referring to another page instead?
Imar
|
|

April 26th, 2010, 04:14 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
chapter 14
Thanks for your help. I will check on that. 
|
|
 |