Ann Onnymoss

Ann Onnymoss

  • NA
  • 1
  • 2.9k

VB Greeting Card Maker - Checkbox and Default Pic

Dec 16 2013 7:27 PM
I have a Greeting Card Maker page that I created in VS. Everything is working exactly as I wanted it to but one thing. The image is loading without the check box to add default pic selected and it is loading on the page load. I followed all of the directions in the book perfectly and I don't know how to fix this now. 

I want the image NOT to load with the page and I want it to load when you select "add the default picture" and then click "update"

Here is a screen shot of what I'm getting now on page load.




Here is the code I wrote out for the ASPX file. 

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

<!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>Greeting Card Maker</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<!--Here are the controls:-->
Choose a backgroud color: <br />
<asp:DropDownList ID="lstBackColor" AutoPostBack="True" runat="server" Width="194px" Height="22px" /> <br /><br />
Choose a font: <br />
<asp:DropDownList ID="lstFontName" runat="server" Width="194px" Height="22px" /><br /><br />
Specify a numeric font size:<br />
<asp:TextBox ID="txtFontSize" runat="server" Width="177px" Height="59px" /><br /><br />
Choose a border style: <br />
<asp:RadioButtonList ID="lstBorder" runat="server" Width="177px" Height="59px" /><br /><br />
<asp:CheckBox ID="chkPicture" runat="server" Text="Add the Default Picture"></asp:CheckBox><br /><br />
Enter the greeting text below:<br />
<asp:TextBox ID="txtGreeting" runat="server" Width="240px" Height="85px" TextMode="MultiLine" /> <br /><br />
<asp:Button ID="cmdUpdate" runat="server" Width="71px" Height="24px" Text="Update" />
</div>

<!--Here is the card: -->
<asp:Panel ID="pnlCard" runat="server" Width="339px" Height="481px" HorizontalAlign="Center" style="position: absolute; top: 16px; left: 313px;">
<br /> 
<asp:Label ID="lblGreeting" runat="server" Width="256px" Height="150px" /><br /><br /><br />
<asp:Image ID="imgDefault" runat="server" Width="212px" Height="160px" />
</asp:Panel>
</form>
</body>
</html>


Here is my ASPX.VB file.

Imports System.Drawing
Imports System.ComponentModel
Imports System.Drawing.Text
Imports System.Drawing.KnownColor
Imports System.Enum

Partial Class GreetingCardMaker
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As EventArgs) Handles Me.Load
If Me.IsPostBack = False Then

'Set color options.
lstBackColor.Items.Add("White")
lstBackColor.Items.Add("Red")
lstBackColor.Items.Add("Green")
lstBackColor.Items.Add("Blue")
lstBackColor.Items.Add("Yellow")

'Set font options.
lstFontName.Items.Add("Times New Roman")
lstFontName.Items.Add("Times New Roman")
lstFontName.Items.Add("Times New Roman")
lstFontName.Items.Add("Times New Roman")

'Set border style options by adding a series of
'ListItem objects.
'Each item indicates the name of the ooptiion, and contains the
' corresponding integer in the Value property.
lstBorder.Items.Add(New _
ListItem(BorderStyle.None.ToString(), BorderStyle.None))
lstBorder.Items.Add(New _
ListItem(BorderStyle.Double.ToString(), BorderStyle.Double))
lstBorder.Items.Add(New _
ListItem(BorderStyle.Solid.ToString(), BorderStyle.Solid))

'Select the first border option.
lstBorder.SelectedIndex = 0

'Set the picture.
imgDefault.ImageUrl = "http://www.jamieandfriends.com/wp-content/uploads/birthday-cake-clipart-4.gif"

'Get the list of color.
Dim colorArray As String() = System.Enum.GetNames(GetType(KnownColor))
lstBackColor.DataSource = colorArray
lstBackColor.DataBind()

'Set border style options.
Dim borderStyleArray As String()
borderStyleArray = System.Enum.GetNames(GetType(BorderStyle))
lstBorder.DataBind()

'Get the list of available fonts, and add them to the font list.
Dim fonts As New InstalledFontCollection()
For Each family As FontFamily In fonts.Families
lstFontName.Items.Add(family.Name)

Next

End If
End Sub

Protected Sub cmdUpdate_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles cmdUpdate.Click


'Refresh the greeting card (because the button was clicked).
UpdateCard()

'Update the color.
pnlCard.BackColor = Color.FromName(lstBackColor.SelectedItem.Text)

'Update the font.
lblGreeting.Font.Name = lstFontName.SelectedItem.Text

If Val(txtFontSize.Text) > 0 Then
lblGreeting.Font.Size = FontUnit.Point(Val(txtFontSize.Text))

End If

'Update the border style.
pnlCard.BorderStyle = Val(lstBorder.SelectedItem.Value)

'Update the picture.
If chkPicture.Checked - True Then
imgDefault.Visible = True
Else
imgDefault.Visible = False
End If

'Set the text.
lblGreeting.Text = txtGreeting.Text

'Find the appropriate TypeConverter for the BorderStyle enumeration.
Dim converter As TypeConverter
converter = CType(TypeDescriptor.GetConverter(GetType(BorderStyle)), _
TypeConverter)

'Update the border style using the value from the converter.
pnlCard.BorderStyle = converter.ConvertFromString(lstBorder.SelectedItem.Text)
End Sub

Protected Sub ControlChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles lstBackColor.SelectedIndexChanged, chkPicture.CheckedChanged, _
txtFontSize.TextChanged, lstBorder.SelectedIndexChanged, _
lstFontName.SelectedIndexChanged,
txtGreeting.TextChanged

'Refresh the greeting card (because a control was changed).
UpdateCard()
End Sub


Private Sub UpdateCard()
' (The code that draws the greeting card goes here.)
End Sub


End Class