I'm having an bit of a problem here. I'm using Web Developer 2005. All I want to do is have an invisible object become visible when I click a button. Pretty simple I'm sure.
Now, I can do this as long as the object is NOT in a gridview where I'm editing a template, case in point:
--------------
1) Button1 example works fine. The label visual property is set to false.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Visible =
True
End SubClick the button, the label appears. No problemo.
------------
2) When I try the exact same thing on a label located in a gridview where I'm editing an item template of a Details view it won't work. It tells me that label2 is not declared...
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
label2.Visible =
"true"
End Sub
As you can see, same code, don't work. So....
--------
3) So, I declared it as I did here with calendar1. However, when I declare it, the old error goes away but now I get...Object reference not set to an instance of an object. All I'm really trying to make a calendar appear at the click of a button to select a date.
Dim calendar1 As Calendar
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
calendar1.Visible = "true"
End Sub1 Partial Class test
2 Inherits System.Web.UI.Page
3
4
5 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
6 Label1.Visible = True
7 End Sub
8
9 Dim calendar1 As Calendar
10
11 Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
12
13 calendar1.Visible = "true"
14
15 End Sub
16
17
18 End Class
19
20
21 HTMl:
22
23 Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>
24
25 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
26
27 <html xmlns="http://www.w3.org/1999/xhtml" >
28 <head runat="server">
29 <title>Untitled Page</title>
30 </head>
31 <body>
32 <form id="form1" runat="server">
33 <div>
34 <asp:Button ID="Button1" runat="server" Text="Button" />
35 <asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
36 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HbAdminMaintenance %>" DeleteCommand="DELETE FROM [HbProducts] WHERE [productID] = @productID" InsertCommand="INSERT INTO [HbProducts] ([source], [productName], [marketingDescription], [categoryID], [manufacturerID], [image1], [image2], [image3], [manufacturer_sku], [manufacurerProductLink], [dateEffective], [dateExpires], [dateAdded], [active], [image4], [productInformation]) VALUES (@source, @productName, @marketingDescription, @categoryID, @manufacturerID, @image1, @image2, @image3, @manufacturer_sku, @manufacurerProductLink, @dateEffective, @dateExpires, @dateAdded, @active, @image4, @productInformation)" SelectCommand="SELECT * FROM [HbProducts]" UpdateCommand="UPDATE [HbProducts] SET [source] = @source, [productName] = @productName, [marketingDescription] = @marketingDescription, [categoryID] = @categoryID, [manufacturerID] = @manufacturerID, [image1] = @image1, [image2] = @image2, [image3] = @image3, [manufacturer_sku] = @manufacturer_sku, [manufacurerProductLink] = @manufacurerProductLink, [dateEffective] = @dateEffective, [dateExpires] = @dateExpires, [dateAdded] = @dateAdded, [active] = @active, [image4] = @image4, [productInformation] = @productInformation WHERE [productID] = @productID">
37 <DeleteParameters>
38 <asp:Parameter Name="productID" Type="Int32" />
39 </DeleteParameters>
40 <UpdateParameters>
41 <asp:Parameter Name="source" Type="String" />
42 <asp:Parameter Name="productName" Type="String" />
43 <asp:Parameter Name="marketingDescription" Type="String" />
44 <asp:Parameter Name="categoryID" Type="Int32" />
45 <asp:Parameter Name="manufacturerID" Type="Int32" />
46 <asp:Parameter Name="image1" Type="String" />
47 <asp:Parameter Name="image2" Type="String" />
48 <asp:Parameter Name="image3" Type="String" />
49 <asp:Parameter Name="manufacturer_sku" Type="String" />
50 <asp:Parameter Name="manufacurerProductLink" Type="String" />
51 <asp:Parameter Name="dateEffective" Type="DateTime" />
52 <asp:Parameter Name="dateExpires" Type="DateTime" />
53 <asp:Parameter Name="dateAdded" Type="DateTime" />
54 <asp:Parameter Name="active" Type="Boolean" />
55 <asp:Parameter Name="image4" Type="String" />
56 <asp:Parameter Name="productInformation" Type="String" />
57 <asp:Parameter Name="productID" Type="Int32" />
58 </UpdateParameters>
59 <InsertParameters>
60 <asp:Parameter Name="source" Type="String" />
61 <asp:Parameter Name="productName" Type="String" />
62 <asp:Parameter Name="marketingDescription" Type="String" />
63 <asp:Parameter Name="categoryID" Type="Int32" />
64 <asp:Parameter Name="manufacturerID" Type="Int32" />
65 <asp:Parameter Name="image1" Type="String" />
66 <asp:Parameter Name="image2" Type="String" />
67 <asp:Parameter Name="image3" Type="String" />
68 <asp:Parameter Name="manufacturer_sku" Type="String" />
69 <asp:Parameter Name="manufacurerProductLink" Type="String" />
70 <asp:Parameter Name="dateEffective" Type="DateTime" />
71 <asp:Parameter Name="dateExpires" Type="DateTime" />
72 <asp:Parameter Name="dateAdded" Type="DateTime" />
73 <asp:Parameter Name="active" Type="Boolean" />
74 <asp:Parameter Name="image4" Type="String" />
75 <asp:Parameter Name="productInformation" Type="String" />
76 </InsertParameters>
77 </asp:SqlDataSource>
78 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
79 <Columns>
80 <asp:CommandField ShowEditButton="True" />
81 <asp:TemplateField HeaderText="dateEffective" SortExpression="dateEffective">
82 <EditItemTemplate>
83 <asp:Calendar ID="Calendar1" runat="server"
84 SelectedDate='<%# Bind("dateEffective") %>' Visible="False"></asp:Calendar>
85 <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("dateEffective") %>' Visible="False"></asp:TextBox>
86 <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
87 </EditItemTemplate>
88 <ItemTemplate>
89 <asp:Label ID="Label1" runat="server" Text='<%# Bind("dateEffective") %>'></asp:Label>
90 </ItemTemplate>
91 </asp:TemplateField>
92 </Columns>
93 </asp:GridView>
94
95 </div>
96 </form>
97 </body>
98 </html>
99