Tuesday, April 13, 2010

April 13, Ajax code

Ajax code



Here is the default aspx

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

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<p>Do you want to submit your information</p>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">
<asp:ListItem Text="yes"></asp:ListItem>
<asp:ListItem Text="no"></asp:ListItem>
</asp:RadioButtonList>
<asp:Panel ID="Panel1" runat="server" Visible="False">
<asp:Label ID="Label1" runat="server" Text="Enter your name"></asp:Label><asp:TextBox
ID="TextBox1" runat="server"></asp:TextBox> <br />
<asp:Label ID="Label2" runat="server" Text="Enter your Address"></asp:Label><asp:TextBox
ID="TextBox2" runat="server"></asp:TextBox>
</asp:Panel>
</ContentTemplate>

</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Here is the VB Code

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
If RadioButtonList1.SelectedIndex = 0 Then
Panel1.Visible = True
Else
Panel1.Visible = False
End If
End Sub
End Class

Controls example



<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" trace="false" EnableViewState="true" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server">

</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:LinkButton ID="LinkButton1" runat="server">Get Choices</asp:LinkButton>

<asp:Calendar ID="Calendar1" runat="server" BackColor="White"
BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana"
Font-Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth"
Width="330px">
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TodayDayStyle BackColor="#999999" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<DayStyle BackColor="#CCCCCC" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
<DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333"
Height="8pt" />
<TitleStyle BackColor="#333399" BorderStyle="Solid" Font-Bold="True"
Font-Size="12pt" ForeColor="White" Height="12pt" />
</asp:Calendar>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Text="Oranges" Value="1.98"></asp:ListItem>
<asp:ListItem Text="Apples" Value="2.89"></asp:ListItem>
<asp:ListItem Text="Bananas" Value=".79"></asp:ListItem>
</asp:CheckBoxList>
<asp:Label ID="lblSelected" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

VB Code

Partial Class _Default
Inherits System.Web.UI.Page
'***********************************
'This page is a mish mash of various controls
'4/13/2010
'steve conger
'**********************************

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'this keeps it from reloading every time the page
'come back from the server
REM this is also a comment
If Not IsPostBack Then
DropDownList1.Items.Add("One")
DropDownList1.Items.Add("Two")
DropDownList1.Items.Add("Three")
End If

' Dim test As String = "This is a long string" & _
' "Here is more of it"

End Sub

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim fruit As String = Nothing
Dim item As ListItem
For Each item In CheckBoxList1.Items
If item.Selected Then
fruit += item.Text & ", " & item.Value & "
"
End If
Next
lblSelected.Text = fruit
End Sub
End Class

No comments:

Post a Comment