I have the following issue, i want to disable or enable a control in my asp form by using asp:checkbox but when i click on the checkbox to change the checked state to true or false, it will always send "false"
<%# Page Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="Registration.aspx.vb" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.auto-style2 {
text-align: left;
}
.auto-style3 {
font-family: "Times New Roman", Times, serif;
}
.auto-style4 {
font-family: "Times New Roman", Times, serif;
font-size: medium;
}
.auto-style5 {
font-family: "Times New Roman", Times, serif;
font-weight: bold;
font-size: x-large;
}
.auto-style6 {
font-size: medium;
}
.auto-style7 {
font-family: "Times New Roman", Times, serif;
font-size: x-large;
text-transform: capitalize;
border-style: outset;
border-width: 3px;
}
.auto-style8 {
width: 351px;
}
.auto-style9 {
width: 344px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="registration" class="auto-style2">
<asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
<br />
<table>
<tr>
<td>Employees in the database:</td>
<td>
<asp:UpdatePanel ID="upddlEmployee" runat="server">
<ContentTemplate>
<asp:DropDownList
ID="drpEmployee"
runat="server"
Height="30px"
Width="175px"
BackColor="White"
CssClass="auto-style2"
ForeColor="#000099"
AutoPostBack="true">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID ="drpEmployee" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
<br />
<br />
<table>
<tr>
<td class="auto-style8">
<asp:Label ID="Label1" runat="server" Text="Employee ID:*" Width="300px"
Font-Bold="True" CssClass="auto-style7" Height="31px" BorderStyle="None"></asp:Label>
</td>
<td class="auto-style9">
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtEmployee_id" runat="server" CssClass="auto-style5" Height="30px" Width="200px" AutoPostBack ="true" OnTextChanged ="txtEmployeeUser_id_TextChanged"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel7" runat="server">
<ContentTemplate>
<span class="auto-style6">
<asp:label
ID="lblEmployeeID"
runat="server"
Text =""
InitialValue="" Width="229px"></asp:label>
</span>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td class="auto-style8"><span class="auto-style6">
<asp:Label ID="Label4" runat="server" Text="First Name:*" Width="300px"
Font-Bold="True" CssClass="auto-style7" height="30px" BorderStyle="None"></asp:Label>
</span>
</td>
<td class="auto-style9">
<asp:TextBox ID="txtFirstName" runat="server" Width="200px" CssClass="auto-style5" height="30px"></asp:TextBox>
</td>
<td>
<span class="auto-style6">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtFirstName" ErrorMessage="First Name Required" CssClass="auto-style3" Width="300px"></asp:RequiredFieldValidator>
</span>
</td>
</tr>
<tr>
<td class="auto-style8">
<span class="auto-style6">
<asp:Label ID="Label5" runat="server" Text=" Last Name:*" Width="300px"
Font-Bold="True" CssClass="auto-style7" height="30px" BorderStyle="None"></asp:Label>
</span>
</td>
<td class="auto-style9">
<asp:TextBox ID="txtLastName" runat="server" Width="200px" CssClass="auto-style5" height="30px"></asp:TextBox>
</td>
<td>
<span class="auto-style6">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtLastName" ErrorMessage="Last Name Required" CssClass="auto-style3" Width="300px"></asp:RequiredFieldValidator>
</span>
</td>
</tr>
<tr>
<td class="auto-style8">
<span class="auto-style6">
<asp:Label ID="lblUsername" runat="server" Text=" User Name:*" Width="300px"
Font-Bold="True" CssClass="auto-style7" height="30px" BorderStyle="None"></asp:Label>
</span></td>
<td class="auto-style9">
<asp:UpdatePanel ID="UpdatePanel6" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtUserName" runat="server" CssClass="auto-style5" height="30px" Width="200px" AutoPostBack ="True" OnTextChanged="txtEmployeeUser_id_TextChanged"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtUserName" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
<td>
<span class="auto-style6">
<asp:label
ID="lblUsernameCheck"
runat="server"
Text =""
InitialValue="" Width="229px"></asp:label>
</span>
</td>
</tr>
<tr>
<td class="auto-style8">
<span class="auto-style6">
<asp:Label ID="Label6" runat="server" Text="Regular Time:" Width="300px"
Font-Bold="True" CssClass="auto-style7" height="30px" BorderStyle="None"></asp:Label>
</span>
</td>
<td class="auto-style9">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtRegularTime" runat="server" CssClass="auto-style5" height="30px" TextMode="Number" Width="200px" AutoPostBack ="True" OnTextChanged ="txtRegularTime_TextChanged"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtRegularTime" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style8">
<span class="auto-style6">
<asp:Label ID="Label7" runat="server" Text="Double Time:" Width="300px"
Font-Bold="True" CssClass="auto-style7" height="30px" BorderStyle="None"></asp:Label>
</span>
</td>
<td class="auto-style9">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtDoubleTime" runat="server" CssClass="auto-style5" height="30px" TextMode="Number" Width="200px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style8">
<span class="auto-style6">
<asp:Label ID="Label8" runat="server" Text="Part Time:" Width="300px"
Font-Bold="True" CssClass="auto-style7" height="30px" BorderStyle="None"></asp:Label>
</span>
</td>
<td class="auto-style9">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtPartTime" runat="server" Width="200px" TextMode="Number" CssClass="auto-style5" height="30px" AutoPostBack ="True" OnTextChanged ="txtPartTime_TextChanged"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtPartTime" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style8">
<span class="auto-style6">
<asp:Label ID="Label9" runat="server" Text="Over time:" Width="300px"
Font-Bold="True" CssClass="auto-style7" height="30px" BorderStyle="None"></asp:Label>
</span>
</td>
<td class="auto-style9">
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtOverTime" runat="server" Width="200px" TextMode="Number" CssClass="auto-style5" height="30px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style8">
<asp:Label ID="Label2" runat="server" Text=" Password:*" Width="231px" Font-Bold="True" CssClass="auto-style7" height="30px" BorderStyle="None"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel8" runat="server">
<ContentTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="chkChecked" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger EventName="CheckedChanged" ControlID ="CheckBox1" />
</Triggers>
</asp:UpdatePanel>
</td>
<td class="auto-style9">
<asp:UpdatePanel ID="UpdatePanel9" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtPassword" runat="server" Width="200px" TextMode="Password" CssClass="auto-style5" height="30px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<span class="auto-style6">
<asp:CustomValidator ID="txtpasswordValidator" runat="server"
ControlToValidate="txtPassword" ErrorMessage="Password Required" CssClass="auto-style3" Width="300px"
OnServerValidate="txtpassword_ServerValidate" >
</asp:CustomValidator>
</span></td>
</tr>
<tr>
<td class="auto-style8">
<span class="auto-style6">
<asp:Label ID="Label3" runat="server" Text=" Confirm Password:*" Width="300px"
Font-Bold="True" CssClass="auto-style7" height="30px" BorderStyle="None"></asp:Label>
</span>
</td>
<td class="auto-style9">
<asp:UpdatePanel ID="UpdatePanel10" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtConfirmpassword" runat="server" Width="200px" TextMode="Password" CssClass="auto-style5" height="30px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<span class="auto-style6">
<asp:CustomValidator
ID="CustomValidator1"
runat="server"
ControlToValidate="txtConfirmpassword"
ErrorMessage="Password mismatch"
OnServerValidate="txtConfirmpassword_ServerValidate"
CssClass="auto-style3"
Width="300px"></asp:CustomValidator>
</span></td>
</tr>
<tr>
<td class="auto-style8">
<asp:Label ID="Label10" runat="server" Text="Label" Visible="False"></asp:Label>
</td>
<td class="auto-style9"> </td>
<td> </td>
</tr>
<tr>
<td class="auto-style8"> </td>
<td class="auto-style9"> </td>
<td> </td>
</tr>
</table>
<br />
<span class="auto-style6">
<br class="auto-style3" />
</span><span class="auto-style4"> </span><span class="auto-style6">
<br class="auto-style3" />
<Table runat="server" >
<tr>
<td>
<asp:Button
ID="btnConfirmPassword"
runat="server"
Text="Confirm Registration"
onclick="Button1_Click"
Font-Bold="True"
Font-Size="X-Large"
Height="50px"
Width="250px" />
</td>
<td>
<asp:Button
ID="btnClear"
runat="server"
Text="ClearData"
onclick="btnClear_Click"
Font-Bold="True"
Font-Size="X-Large"
Height="50px"
Width="250px" />
</td>
</tr>
</Table>
</span>
</div>
</asp:Content>
and the code that is invoqued by the asp is the following:
Imports System.Data
Imports System.Configuration
Imports MySql.Data.MySqlClient
Partial Class Default2
Inherits System.Web.UI.Page
Dim gclass As New GlobalClass
Dim employeeData As New Employee
Dim intEmployee() As Integer
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles btnConfirmPassword.Click
If drpEmployee.SelectedIndex = -1 Then
ExeQuery("I")
Else
ExeQuery("U")
End If
clearFields()
End Sub
Sub ExeQuery(strMode As String)
If txtRegularTime.Text <> "" Then
Dim query As String = gclass.SPEmployeeCall(strMode, 1, txtUserName.Text, txtPassword.Text, txtConfirmpassword.Text, _
txtEmployee_id.Text, txtFirstName.Text, txtLastName.Text, _
Convert.ToDouble(txtOverTime.Text), Convert.ToDouble(txtDoubleTime.Text), _
Convert.ToDouble(txtPartTime.Text), Convert.ToDouble(txtRegularTime.Text))
gclass.ExecuteSP(query)
End If
End Sub
Protected Sub txtRegularTime_TextChanged(sender As Object, e As EventArgs) Handles txtRegularTime.TextChanged
If Convert.ToDecimal(txtRegularTime.Text) > 0 Then
txtDoubleTime.Text = Convert.ToDecimal(txtRegularTime.Text * 2)
txtOverTime.Text = Convert.ToDecimal(txtRegularTime.Text * 1.5)
txtPartTime.Text = 0
End If
txtPassword.Focus()
End Sub
Protected Sub txtPartTime_TextChanged(sender As Object, e As EventArgs) Handles txtPartTime.TextChanged
If Convert.ToDecimal(txtPartTime.Text) > 0 Then
txtDoubleTime.Text = 0
txtOverTime.Text = 0
txtRegularTime.Text = 0
End If
txtPassword.Focus()
End Sub
Sub clearFields()
drpEmployee.SelectedIndex = 0
checkboxDRPemployee()
txtEmployee_id.Text = Nothing
txtFirstName.Text = Nothing
txtLastName.Text = Nothing
txtUserName.Text = Nothing
txtDoubleTime.Text = Nothing
txtOverTime.Text = Nothing
txtRegularTime.Text = Nothing
txtPartTime.Text = Nothing
End Sub
Sub clearFields(dt As DataTable)
txtEmployee_id.Text = dt.Rows(0)(1)
txtFirstName.Text = dt.Rows(0)(2)
txtLastName.Text = dt.Rows(0)(3)
txtUserName.Text = dt.Rows(0)(8)
txtDoubleTime.Text = dt.Rows(0)(5)
txtOverTime.Text = dt.Rows(0)(4)
txtRegularTime.Text = dt.Rows(0)(7)
txtPartTime.Text = dt.Rows(0)(6)
txtPassword.Text = dt.Rows(0)(9)
txtConfirmpassword.Text = dt.Rows(0)(10)
End Sub
Protected Sub txtEmployeeUser_id_TextChanged(sender As Object, e As EventArgs) Handles txtEmployee_id.TextChanged, txtUserName.TextChanged
Dim intMode As Integer
If sender Is txtEmployee_id Then
intMode = 2
ElseIf sender Is txtUserName Then
intMode = 3
End If
Dim query As String = gclass.SPEmployeeCall("Q", intMode, txtUserName.Text, Nothing, Nothing, _
txtEmployee_id.Text, Nothing, Nothing, _
Nothing, Nothing, _
Nothing, Nothing)
lblEmployeeID.Visible = True
lblEmployeeID.Text = gclass.DatabaseMessages(query)
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Session.Contents("Employee") Is Nothing Then
Response.Redirect("Login.aspx")
Else
employeeData = Session("Employee")
End If
If Not IsPostBack And drpEmployee.SelectedIndex = -1 Then
Session.Contents("EmployeeDDL") = gclass.LoadEmployeeAbsent(drpEmployee, 99)
End If
checkboxDRPemployee()
End Sub
Protected Sub drpEmployee_SelectedIndexChanged(sender As Object, e As EventArgs) Handles drpEmployee.SelectedIndexChanged
intEmployee = Session.Contents("EmployeeDDL")
If drpEmployee.SelectedIndex <> 0 Then
Dim query As String = gclass.SPEmployeeCall("Q", 7, Nothing, Nothing, Nothing, intEmployee(drpEmployee.SelectedIndex), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
Dim dt As DataTable = gclass.Mysql_CreateDataTable(query)
clearFields(dt)
Else
clearFields()
End If
End Sub
Sub checkboxDRPemployee()
If drpEmployee.SelectedIndex <> 0 Then
CheckBox1.Enabled = True
CheckBox1.Checked = False
Else
CheckBox1.Enabled = False
CheckBox1.Checked = False
End If
End Sub
Protected Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
clearFields()
End Sub
Protected Sub txtpassword_ServerValidate(source As Object, args As ServerValidateEventArgs)
If Not CheckBox1.Checked Then
args.IsValid = (txtPassword.Text <> "")
End If
End Sub
Protected Sub txtConfirmpassword_ServerValidate(source As Object, args As ServerValidateEventArgs)
If Not CheckBox1.Checked Then
args.IsValid = (txtPassword.Text = txtConfirmpassword.Text)
End If
End Sub
Protected Sub chkChecked(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
Dim thisValue As Boolean = CheckBox1.Checked
txtPassword.Enabled = CheckBox1.Checked
txtConfirmpassword.Enabled = CheckBox1.Checked
End Sub
End Class
Thank you in advance
Kindest Regards
Douglas Leekam
This definitely has something to do with AutoPostBack="true"
Try to debug by changing to:
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="chkChecked" />
Not sure what the functionality of your code is, but you might want to wrap page load code inside
If Not Page.IsPostBack Then
// code currently in page load
End If
You can use javascript to check whether checkbox is checked or not based on value you can disable the control from javascript itself. You can use javascript onchange event to check checkbox value.
Related
Please help. I am trying to make the rejectcheckbox become invisible based on the CaseStatus item. If CaseStaus = "success" then rejectcheckbox's visible = true. If CaseStatus = "reject" then rejectcheckbox's visible = false.
<ItemTemplate>
<tr
style="">
<td>
<asp:Label ID="emailaddressLabel" runat="server" Text='<%# Eval("emailaddress") %>' />
</td>
<td>
<asp:Label ID="CaseNumberLabel" runat="server" Text='<%# Eval("CaseNumber") %>' />
</td>
<td>
<asp:Label ID="FileUploadToRepositoryTimeLabel" runat="server" Text='<%# Eval("FileUploadToRepositoryTime") %>' />
</td>
<td>
<asp:Label ID="CaseTitleLabel" runat="server" Text='<%# Eval("CaseTitle") %>' />
</td>
<td>
<asp:Label ID="CaseTypeLabel" runat="server" Text='<%# Eval("CaseType") %>' />
</td>
<td>
<asp:HyperLink ID="FileNameLabel" runat="server" Text='<%# Eval("FileName") %>' target ="_blank" NavigateUrl='<%# "~/FileArchives/FileUploadArchive/" + Eval("FileName")%>' Visible='<%# !string.IsNullOrWhiteSpace(Eval("FileName").ToString()) %>'></asp:HyperLink>
</td>
<td style="padding-right: 5px; padding-left: 5px">
<asp:Label ID="CaseStatusLabel" runat="server" Text='<%# Eval("CaseStatus") %>' Font-Bold="True" style='<%# GetUserStatusStyle() %>'/>
</td>
<td>
<asp:LinkButton ID="SessionLinkButton" runat="server" Text='Update' CommandArgument='<%# Eval("SessionId") %>' />
<%--<asp:Label ID="SessionIdLabel" runat="server" Text='<%# Eval("SessionId") %>' />--%>
</td>
<td style="text-align: center">
<asp:CheckBox ID="rejectCheckBox" runat="server" Checked='<%# Eval("reject") %>' OnCheckedChanged="updateRejectStatus_CheckedChanged" Enabled="True" AutoPostBack="True"/>
<%-- <asp:CheckBox ID="rejectCheckBox" runat="server" Checked='<%# Eval("reject") %>' Enabled="True" AutoPostBack="False" />--%>
</td>
</tr>
</ItemTemplate>
Use the on-item data bound event.
So, say I have this markup:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID" >
<ItemTemplate>
<tr style="">
<td><asp:Label ID="First" runat="server" Text='<%# Eval("FirstName") %>' /></td>
<td><asp:Label ID="Last" runat="server" Text='<%# Eval("LastName") %>' /></td>
<td><asp:Label ID="Hotel" runat="server" Text='<%# Eval("HotelName") %>' /></td>
<td><asp:Label ID="City" runat="server" Text='<%# Eval("City") %>' /></td>
<td align="center">
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" class="table table-hover">
<tr runat="server" style="">
<th runat="server">FirstName</th>
<th runat="server">LastName</th>
<th runat="server">HotelName</th>
<th runat="server">City</th>
<th runat="server">Select</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
Code to load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid
End If
End Sub
Sub LoadGrid()
Using cmdSQL As New SqlCommand("SELECT * FROM tblHotels ORDER BY HotelName",
New SqlConnection(My.Settings.TEST4))
cmdSQL.Connection.Open()
ListView1.DataSource = cmdSQL.ExecuteReader
ListView1.DataBind()
End Using
End Sub
Output:
Now, lets say for city = "Banff", we want to hide the check box.
So, in data bound event, we could use this:
Protected Sub ListView1_ItemDataBound(sender As Object, e As ListViewItemEventArgs) Handles ListView1.ItemDataBound
If e.Item.GetType = GetType(ListViewDataItem) Then
Dim txtCity As Label = e.Item.FindControl("City")
Dim ckbox As CheckBox = e.Item.FindControl("CheckBox1")
If txtCity.Text = "Banff" Then
ckbox.Visible = False
End If
End If
End Sub
So, now we see this:
so, as a general rule to change color, hide controls etc?
Use the ItemDataBound event.
How can I fix this form, I need to redirect the result to a different page after the button "Display offer is pressed"; the main problem here is that I can't save the data and redirecting it. The 2nd page should look something like this:
The price for the vehicle you have configured is [All the options selected/computed]
The offer was issued on [Calendar date1] and remains valid until [Calendar date2]
I have tested something using Cache...still no result.
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
GetData()
End Sub
1 reference
Private Sub GetData()
lblName.Text = Cache("Name").ToString
1blPrice.Text = Cache("Price").ToString
lblofferDate.Text = Cache("offerDate").ToString
1blofferExpiration.Text = Cache("ExpirationDate").ToString
End Sub
1st page - Main FORM.
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 204px;
}
.auto-style3 {
text-decoration: underline;
}
.auto-style4 {
width: 843px;
border-collapse: collapse;
}
.auto-style5 {
height: 24px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:Label ID="Label1" runat="server" Text="Last Name:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label2" runat="server" Text="First Name:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label3" runat="server" Text="Offer date:"></asp:Label>
</td>
<td>
<asp:Calendar ID="calOfferDate" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" Width="200px">
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<NextPrevStyle VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#808080" />
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<SelectorStyle BackColor="#CCCCCC" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<WeekendDayStyle BackColor="#FFFFCC" />
</asp:Calendar>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label4" runat="server" Text="Offer expiration date:"></asp:Label>
</td>
<td>
<asp:Calendar ID="calExpirationDate" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" Width="200px">
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<NextPrevStyle VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#808080" />
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<SelectorStyle BackColor="#CCCCCC" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<WeekendDayStyle BackColor="#FFFFCC" />
</asp:Calendar>
</td>
</tr>
</table>
<hr />
</div>
<p class="auto-style3">
<strong>Set up your car</strong></p>
<table class="auto-style4">
<tr>
<td class="auto-style5">
<asp:Label ID="Label5" runat="server" Text="Equipment level"></asp:Label>
</td>
<td class="auto-style5">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="20,000">Standard</asp:ListItem>
<asp:ListItem Value="22,000">Evolved</asp:ListItem>
<asp:ListItem Value="27,000">Advanced</asp:ListItem>
<asp:ListItem Value="32,000">Premium</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text="Warranty type"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem>Standard (2 years)</asp:ListItem>
<asp:ListItem>Extended (5 years)</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Text="Optionals"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="rblOptionals" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True">Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
<asp:CheckBoxList ID="cblOptionals" runat="server" RepeatDirection="Horizontal" Width="727px">
<asp:ListItem Value="1,000">Alloys wheels</asp:ListItem>
<asp:ListItem Value="1,500">Climatronic</asp:ListItem>
<asp:ListItem Value="1,300">Automatic pilot</asp:ListItem>
<asp:ListItem Value="1,000">Road alert</asp:ListItem>
<asp:ListItem Value="850">Navigation</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td class="auto-style5">
<asp:Label ID="Label8" runat="server" Text="Discounts"></asp:Label>
</td>
<td class="auto-style5"><strong><em>
<asp:CheckBoxList ID="cbListDiscounts" runat="server" RepeatDirection="Horizontal" CssClass="auto-style5" Width="394px" TextAlign="Left">
<asp:ListItem>Whole payment</asp:ListItem>
<asp:ListItem>CASCO insurance</asp:ListItem>
</asp:CheckBoxList>
</em></strong></td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnDisplayOffer" runat="server" BackColor="Red" ForeColor="#CCCCCC" Height="20px" Text="Display offer" Width="101px" />
</td>
</tr>
</table>
</form>
</body>
</html>
Display button in FORM
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnDisplayOffer_Click(sender As Object, e As EventArgs) Handles btnDisplayOffer.Click
Response.Redirect("Offer.aspx")
End Sub
Public Sub CreateCache()
Cache("Name") = txtFirstName.Text & " " & txtLastName.Text
Cache("offerDate") = calOfferDate.SelectedDate
Cache("ExpirationDate") = calExpirationDate.SelectedDate
Dim price As Integer
If DropDownList1.Items(0).Selected = True Then
price = 20000
ElseIf DropDownList1.Items(1).Selected = True Then
price = 22000
ElseIf DropDownList1.Items(2).Selected = True Then
price = 27000
Else
price = 32000
End If
If RadioButtonList1.Items(1).Selected = True Then
price = price + 2000
End If
If cbListDiscounts.Items(0).Selected = True Then
price = price - (price * 0.1)
End If
If cbListDiscounts.Items(1).Selected = True Then
price = price - 1000
End If
End Sub
Protected Sub rblOptionals_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rblOptionals.SelectedIndexChanged
If rblOptionals.SelectedValue.Equals("Yes") Then
cblOptionals.Visible = True
Else
cblOptionals.Visible = False
End If
End Sub
End Class
Just code out your button code. You click on that button - it saves some data, and then does a simple response.Redirect.
Protected Sub btnDisplayOffer_Click(sender As Object, e As EventArgs) Handles btnDisplayOffer.Click
SaveMyData
Response.Redirect("Offer.aspx")
End Sub
Sub SaveMyData
Session("Name") = txtFirstName.Text & " " & txtLastName.Text
Session("offerDate") = calOfferDate.SelectedDate
Session("ExpirationDate") = calExpirationDate.SelectedDate
.etc .etc. etc.
End Sub
Now, in the target page, you can in on-load do this:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
if IsPostBack = False then
GetData()
end if
End Sub
Private Sub GetData()
lblName.Text = Session("Name")
1blPrice.Text = Session("Price")
lblofferDate.Text = Session("offerDate")
1blofferExpiration.Text = Session("ExpirationDate")
End Sub
and as noted always remember to check IsPostPack = False. That is your FIRST one time page load - so inside of that code block then becomes just like say a VB6 or ms-access form load event - the first time is where your load up code goes - without that if IsPostBack = False, then that code will run every time - including for buttons etc. that you drop on the form - and thus those controls will be re-set each time you use a button or any event on that page - as a coding habit - put your page load up code inside of the IsPostBack=False code stub - do NOT forget to have that code block - make it habit - even when you think you don't need to!!!!
I'm just trying to get accustomed to LVs and I just threw this one together. I was under the impression that the LV would handle the inserting and refreshing of the LV after the insert but it doesn't appear to be the case. I even added the LV.rebind() and still nothing..
I get the LV to refresh/rebind properly after the first insert but subsequent inserts does not produce a refreshed LV. I have confirmed that the records are inserted properly into the database.
Here is my code so far, do I
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ProductID" EnableViewState="true"
datasourceid="sqlDS" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<tr style="">
<td>
</td>
<td>
<asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
</td>
<td>
<asp:Label ID="CategoryLabel" runat="server" Text='<%# Eval("Category") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
</td>
<td>
<asp:Label ID="CostLabel" runat="server" Text='<%# Eval("Cost") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
</td>
<td>
<asp:Label ID="ProductIDLabel1" runat="server"
Text='<%# Eval("ProductID") %>' />
</td>
<td>
<asp:TextBox ID="CategoryTextBox" runat="server"
Text='<%# Bind("Category") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
</td>
<td>
<asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</td>
<td>
</td>
<td>
<asp:TextBox ID="CategoryTextBox" runat="server"
Text='<%# Bind("Category") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
</td>
<td>
<asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
</td>
<td>
<asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
</td>
<td>
<asp:Label ID="CategoryLabel" runat="server" Text='<%# Eval("Category") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
</td>
<td>
<asp:Label ID="CostLabel" runat="server" Text='<%# Eval("Cost") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">
</th>
<th runat="server">
ProductID</th>
<th runat="server">
Category</th>
<th runat="server">
Description</th>
<th runat="server">
Cost</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="sqlDS" runat="server"
DataSourceMode="DataSet" EnableCaching="true"
ConnectionString="<%$ ConnectionStrings:ProjectDashboardConnectionString %>"
SelectCommand="usp_CafeteriaGetProducts" SelectCommandType="StoredProcedure"
FilterExpression="Category='A'"
InsertCommand="usp_CafeteriaInsertProducts" InsertCommandType="StoredProcedure">
<InsertParameters>
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Category" Type="String" />
<asp:Parameter Name="Cost" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
code beind:
Public Class WebForm3
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub ListView1_ItemInserted(ByVal sender As Object, ByVal e As ListViewInsertedEventArgs) Handles ListView1.ItemInserted
sqlDS.Dispose()
sqlDS.DataBind()
ListView1.Dispose()
ListView1.DataSourceID = "sqlDS"
ListView1.DataBind()
End Sub
Protected Sub sqlProducts_ItemInserting(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs) Handles sqlDS.Inserting
''Do something
End Sub
Protected Sub sqlProducts_ItemInserted(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs) Handles sqlDS.Inserted
''Do something
End Sub
End Class
any ideas?
Thanks.
It was because of the sqldatasource property EnableCaching being set to "true". Removed that property completely as the default is False.
I have a List of Client Displayed in Repeater. I have a Details Button in Repeater which displays the Details of Client when Clicked. For Sample now just added 'ClientName' only. *When i Click on 'Details' LinkButton in Repeater it Displays the Details of Selected Row. But, this causes FullPage Post Back! Which i want to Prevent. Just i want to Update the Panel which displays the Details when row is selected from Repeater*.
In .aspx page:
<script>
function ShowPopUp() {
var listItemsRegion = document.getElementById('popup');
popup.style.display = "block";
}
function ClosePopup() {
var listItemsRegion = document.getElementById('popup');
popup.style.display = "none";
}
</script>
<asp:Repeater ID="RepDetails" runat="server" OnItemCommand="RepDetails_ItemCommand">
<HeaderTemplate>
<table class="tabl">
<tr style="background-color: #808080; color: White">
<td class="lblCenter">
<asp:Label ID="Label4" runat="server" Text="City" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label3" runat="server" Text="Age" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label1" runat="server" Text="Gender" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label5" runat="server" Text="Details" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="<%# Container.ItemIndex % 2 == 0 ? "rowEven" : "rowOdd" %>">
<td class="lblCenter">
<asp:Label ID="lblCity" runat="server" Text='<%#Eval("City") %>' /></td>
<td class="lblCenter">
<asp:Label ID="lblAge" runat="server" Text='<%#Eval("Age") %>' /></td>
<td class="lblCenter">
<asp:Label ID="lblGen" runat="server" Text='<%#Eval("Gender") %>' CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:LinkButton ID="lblDetails" runat="server" CommandName="Display"
CommandArgument='<%#Eval("ID") %>'>Details</asp:LinkButton></td>
<asp:Label ID="rlblClientname" runat="server" Text='<%#Eval("Client") %>' Visible="false"></asp:Label>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<div id="popup" style="display: none">
<asp:UpdatePanel ID="UpdatePanel6" runat="server">
<ContentTemplate>
<table width="80%" align="center">
<tr>
<td> </td>
<td width="30%"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<asp:Label ID="Label15" runat="server" CssClass="lbl" Text="Client Code"></asp:Label>
</td>
<td>
<asp:Label ID="lblClientName" runat="server" CssClass="lbl"></asp:Label>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input id="Button2" type="button" value="Close" onclick="ClosePopup();" class="but" /> </td>
</tr>
</table>
</ContentTemplate>
<%-- <Triggers>
<asp:AsyncPostBackTrigger ControlID="RepDetails" EventName="RepDetails_ItemCommand" />
</Triggers>--%>
</asp:UpdatePanel>
</div>
In Repeater Item Command:
protected void RepDetails_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Display")
{
LinkButton lblDetails = (LinkButton)e.Item.FindControl("lblDetails");
Label rlblClientname = (Label)e.Item.FindControl("rlblClientname");
if (lblDetails != null && e.CommandArgument != null)
{
string val = e.CommandArgument.ToString();
if (rlblClientname != null && rlblClientname.Text != string.Empty)
{
lblClientName.Text = rlblClientname.Text;
}
string scrpt = "ShowPopUp();";
Page.ClientScript.RegisterStartupScript(this.GetType(), "s", scrpt, true);
}
}
}
This causes Full Page Post Back Which i want to Prevent.Onclick of Repeater row the details must be displayed with AsynPostBack. When adding Trigger Event to 'popup' div then it say control could not be found
Help Appreciated!
Thanks!
You have one of two Options:
1) Uncomment this code and change EventName="RepDetails_ItemCommand" to EventName="ItemCommand"
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RepDetails" EventName="ItemCommand" />
</Triggers>
2) Put the Repeater in the <ContentTemplate> of the UpdatePanel
In the 2nd step of the wizard, I have a dropdownlist that is populated from the db. when I go to the 3rd step RegisterUser.ActiveStepChanged event if fired. In there I save the data to the db. My textboxes are saving properly but my the vb code isn't pulling the selectedIndex/Value from the dropdown.
I tried populating the dropdown in Load, PreRender and neither of them helped. I also did if not Postback which didn't help either.
Any ideas?
Here is the code Sample:
Thanks.
Asp.net - It only includes relevant code:
<%# Page Title="Register" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeBehind="Register.aspx.vb" Inherits="Events.Register" EnableEventValidation="false" Trace="true" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="../Scripts/CommonScripts.js">
</script>
<style type="text/css">
.textInput {
width: 150px;
}
.dropdownField
{
width: 155px;
}
</style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="False"
Height="68px" Width="70%" >
<FinishNavigationTemplate>
<table cellpadding="5px" width="100%">
<tr>
<td align="center" width="50%">
<asp:Button ID="FinishButton" runat="server" CommandName="MoveComplete"
Text="Finish" onclick="RegisterUser_ActiveStepChanged" /></td>
</tr>
</table>
</FinishNavigationTemplate>
<LayoutTemplate>
<asp:PlaceHolder ID="wizardStepPlaceholder" runat="server"></asp:PlaceHolder>
<asp:PlaceHolder ID="navigationPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<WizardSteps>
<asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
<ContentTemplate>
<table style="font-size:100%;height:100%;width:100%;">
<tr>
<td align="center" colspan="2">
Sign Up for Your New Account</td>
</tr>
<tr>
<td align="right" style="width:40%">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmPasswordLabel" runat="server"
AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"
ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required."
ToolTip="Confirm Password is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
</td>
<td>
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server"
ControlToValidate="Email" ErrorMessage="E-mail is required."
ToolTip="E-mail is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security Question:</asp:Label>
</td>
<td>
<asp:TextBox ID="Question" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="QuestionRequired" runat="server"
ControlToValidate="Question" ErrorMessage="Security question is required."
ToolTip="Security question is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security Answer:</asp:Label>
</td>
<td>
<asp:TextBox ID="Answer" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server"
ControlToValidate="Answer" ErrorMessage="Security answer is required."
ToolTip="Security answer is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server"
ControlToCompare="Password" ControlToValidate="ConfirmPassword"
Display="Dynamic"
ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="RegisterUser"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
<CustomNavigationTemplate>
<table border="0" cellspacing="5" style="width:100%;height:100%;">
<tr align="right">
<td align="center" colspan="0">
<asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext"
Text="Create User" ValidationGroup="RegisterUser" />
</td>
</tr>
</table>
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
<asp:WizardStep runat="server" Title="General Information" StepType="Finish"
ID="GeneralInfo">
<table style="font-size:100%; width:100%; height:100%">
<tr>
<td align="center" colspan="2">
Please Add Additional Account Information</td>
</tr>
<td align="right">
Birthday:
</td>
<td>
<asp:TextBox class="textInput" ID="Birthday" runat="server"></asp:TextBox>
<asp:ImageButton ID="BirthdayButton" runat="server" ImageUrl="~/Images/Calendar.png" Height="24" Width="24" ImageAlign="Baseline" />
<asp:CalendarExtender TargetControlID="Birthday" ID="BirthdayExtender" runat="server" PopupButtonID="BirthdayButton" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="Birthday" ErrorMessage="Birthday is required."
ToolTip="Birthday is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
Religious Observance:
</td>
<td>
<asp:DropDownList class="dropdownField" ID="ReligiousObservance" runat="server"
DataSourceID="HashkafaDataSource" DataTextField="chvDescription"
DataValueField="intReligiousMasterID" AppendDataBoundItems="true" >
<asp:ListItem Value="0">Select One</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="HashkafaDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:EventsDB.06-ConnectionString %>"
SelectCommand="select s.chvSiteName, r.intReligiousMasterID, r.chvDescription from
tblSiteMaster as s inner join tblSiteReligious as sr on s.intSiteID=sr.intSiteID
inner join tblReligiousMaster as r on r.intReligiousMasterID=sr.intReligiousMasterID
where s.intSiteID=cast(#SiteID As int)">
<SelectParameters>
<asp:Parameter Name="SiteID"/>
</SelectParameters>
</asp:SqlDataSource>
<asp:RequiredFieldValidator ID="ReligiousObservanceRequired" runat="server"
ControlToValidate="ReligiousObservance" ErrorMessage="Religious Observance is required."
ToolTip="Religious Observance is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
<%-- <CustomNavigationTemplate/> --%>
</asp:WizardStep>
<asp:CompleteWizardStep runat="server">
<ContentTemplate>
<table style="font-size:100%;height:68px;width:70%;">
<tr>
<td>
Your account has been successfully created.</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="ContinueButton" runat="server" CausesValidation="False"
CommandName="Continue" Text="Continue" ValidationGroup="RegisterUser" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
<StartNavigationTemplate>
hello<br />
</StartNavigationTemplate>
<StepNavigationTemplate>
<table cellpadding="5px" width="100%">
<tr>
<td align="right"><asp:Button ID="StepPreviousButton" runat="server" CausesValidation="False"
CommandName="MovePrevious" Text="Previous" /> </td>
<td align="left"> <asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext"
Text="Next" Height="20" Width="18" /> </td> </tr>
</table>
</StepNavigationTemplate>
</asp:CreateUserWizard>
</asp:Content>
VB.net code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'If (Not IsPostBack) Then
' PopulateReligiousDropdown()
'End If
'Scripts for state and country drop down
' Commented out because doing in ASP.Net
' Page.ClientScript.RegisterStartupScript(Me.GetType(), _
' "MyScript", _
' "window.onload=init();" & _
' "function init() { " & _
' "fillList(document.getElementById('MainContent_RegisterUser_dropCountry'), areas[5]);" & _
' "fillList(document.getElementById('MainContent_RegisterUser_dropState'), areas[0]);" & _
'" }", True)
PhotoUploadValidator.ValidationExpression = HelperMethods.regexPhotos.ToString()
RegisterUser.ContinueDestinationPageUrl = Request.QueryString("ReturnUrl")
' Populate ReligiousDropdown
HelperMethods.SiteID = HelperMethods.GetSiteID("Request.Url.Host")
HashkafaDataSource.SelectParameters.Item(0).DefaultValue = HelperMethods.SiteID
End Sub
Protected Sub RegisterUser_ActiveStepChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RegisterUser.ActiveStepChanged
' Have we JUST reached the Complete step?
If RegisterUser.ActiveStep.Title = "General Information" Then
'PopulateReligiousDropdown()
End If
If RegisterUser.ActiveStep.Title = "Complete" Then
Dim GeneralInfo As WizardStep = CType(RegisterUser.FindControl("GeneralInfo"), WizardStep)
' Programmatically reference the TextBox controls
Dim LastName As TextBox = CType(GeneralInfo.FindControl("LastName"), TextBox)
Dim FirstName As TextBox = CType(GeneralInfo.FindControl("FirstName"), TextBox)
Dim dropCountry As DropDownList = CType(GeneralInfo.FindControl("dropCountry"), DropDownList)
Dim dropState As DropDownList = CType(GeneralInfo.FindControl("dropState"), DropDownList)
Dim City As TextBox = CType(GeneralInfo.FindControl("City"), TextBox)
Dim ZipCode As TextBox = CType(GeneralInfo.FindControl("ZipCode"), TextBox)
Dim Address As TextBox = CType(GeneralInfo.FindControl("Address"), TextBox)
Dim Phone As TextBox = CType(GeneralInfo.FindControl("Phone"), TextBox)
Dim Birthday As TextBox = CType(GeneralInfo.FindControl("Birthday"), TextBox)
Dim ReligiousObservance As DropDownList = CType(GeneralInfo.FindControl("ReligiousObservance"), DropDownList)
' Dim PhotoUpload As TextBox = CType(GeneralInfo.FindControl("PhotoUpload"), TextBox)
' Update the UserProfiles record for this user
' Get the UserId of the just-added user
Dim newUser As MembershipUser = Membership.GetUser
Dim newUserId As Guid = CType(newUser.ProviderUserKey, Guid)
' Insert a new record into UserProfiles
Dim connectionString As String = ConfigurationManager.ConnectionStrings("EventsDB.06-ConnectionString").ConnectionString
Dim updateSql As String = "Insert into tblUsers " & _
"Values (#UserId, GETDATE(), #FirstName, #LastName, #dropCountry, #dropState, #City, #ZipCode, #Address, #Phone, #Birthday, #ReligiousObservance)"
Using myConnection As New SqlConnection(connectionString)
myConnection.Open()
Dim myCommand As New SqlCommand(updateSql, myConnection)
myCommand.Parameters.AddWithValue("#UserId", newUserId)
myCommand.Parameters.AddWithValue("#LastName", LastName.Text.Trim())
myCommand.Parameters.AddWithValue("#FirstName", FirstName.Text.Trim())
myCommand.Parameters.AddWithValue("#dropCountry", dropCountry.SelectedValue)
myCommand.Parameters.AddWithValue("#dropState", dropState.SelectedValue)
myCommand.Parameters.AddWithValue("#City", City.Text.Trim())
myCommand.Parameters.AddWithValue("#ZipCode", ZipCode.Text.Trim())
myCommand.Parameters.AddWithValue("#Address", Address.Text.Trim())
myCommand.Parameters.AddWithValue("#Phone", Phone.Text.Trim())
myCommand.Parameters.AddWithValue("#Birthday", Birthday.Text.Trim())
myCommand.Parameters.AddWithValue("#ReligiousObservance", ReligiousObservance.SelectedIndex)
'The dropdown's are not populating the server. The Value isn't being passed
' and I don't know why?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
myCommand.ExecuteNonQuery()
myConnection.Close()
End Using
End If
End Sub