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!!!!
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.
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.
I am making an ASP.Net VB web application and I am trying to upload files to the server. There is a modal popup and inside of the popup it will display an image if it exists, If it does not exist you can upload an image. The trouble is that Whenever I hit the upload button no file uploads. The page refreshes and the popup disappears. I just want it so at least the file uploads properly.
This is the asp code for the pop up
<div id="openModal" class="modalDialog">
<div>
X
<h2>Transaction Recipt</h2>Transaction ID:
<asp:Label ID="Label2" runat="server" Text=''></asp:Label>
<br /><br />
<asp:Image ID="Image1" runat="server" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br /><br />
<br />
<asp:FileUpload id="FileUploadControl" runat="server" />
<br /><br />
<asp:Button ID="Button2" runat="server" Text="Upload" OnClick = "Button_Upload" CommandArgument = '<%# Eval("Row") %>' Width="75" /><br>
<asp:Label ID="Label3" runat="server" Text=""></asp:Label>
</div>
This is the vb code for the file upload
Protected Sub Button_Upload(ByVal sender As Object, ByVal e As EventArgs)
If FileUploadControl.HasFile Then
Try
FileUploadControl.SaveAs("~\Images\" & _
FileUploadControl.FileName)
Label1.Text = "File name: " & _
FileUploadControl.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUploadControl.PostedFile.ContentLength & " kb<br>" & _
"Content type: " & _
FileUploadControl.PostedFile.ContentType
Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "You have not specified a file."
End If
End Sub
And this is the asp code for the whole page in case you need it
<%# Page Title="" Language="VB" MasterPageFile="~/Admin.master" AutoEventWireup="false"
CodeFile="Ledger.aspx.vb" Inherits="Admin_Accounting_Ledger" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<link href="../../Styles/Admin.css" rel="Stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Account] FROM [Accounts]"></asp:SqlDataSource>
<table style="width:100%;">
<tr>
<td class="style1">
<asp:DropDownList ID="DropDownList1" runat="server" ViewStateMode="Enabled"
Width="241px" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="Account" DataValueField="Account">
</asp:DropDownList>
<br />
</td>
<td class="style2">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
CellPadding="2" DataSourceID="SqlDataSource3" ForeColor="Black"
GridLines="None" Height="30px" Width="241px">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<EditRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<Fields>
<asp:BoundField DataField="Column1" HeaderText="Account Total" ReadOnly="True"
SortExpression="Column1" />
</Fields>
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
</asp:DetailsView>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Add Transaction"
BackColor="#CCCCCC" />
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT SUM(Amount) FROM Transactions WHERE ([Account] LIKE '%' + #Account + '%')">
<SelectParameters>
<asp:QueryStringParameter Name="Account" QueryStringField="id" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
<table style="width: 100%;">
<tr>
<td align="center" width="150px">
<%# Eval("Date")%>
</td>
<td align="center" width="200px">
<%# Eval("Category")%>
</td>
<td align="center" >
<%# Eval("Amount")%>
</td>
<td align="Right" >
<asp:Button ID="Button2" runat="server" Text="Reciept" OnClick = "Button_Reciept" CommandArgument = '<%# Eval("Row") %>' Width="75" /><br>
</td>
</tr>
</table>
<br/>
</ItemTemplate>
</asp:Repeater>
<div id="openModal" class="modalDialog">
<div>
X
<h2>Transaction Recipt</h2>Transaction ID:
<asp:Label ID="Label2" runat="server" Text=''></asp:Label>
<br /><br />
<asp:Image ID="Image1" runat="server" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br /><br />
<br />
<asp:FileUpload id="FileUploadControl" runat="server" />
<br /><br />
<asp:Button ID="Button2" runat="server" Text="Upload" OnClick = "Button_Upload" CommandArgument = '<%# Eval("Row") %>' Width="75" /><br>
<asp:Label ID="Label3" runat="server" Text=""></asp:Label>
</div>
</div>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Date], [Amount], [Category], [Row] FROM [Transactions] WHERE ([Account] LIKE '%' + #Account + '%') ORDER BY Date DESC">
<SelectParameters>
<asp:QueryStringParameter Name="Account" QueryStringField="id" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
Thank you
1- If you are using an update panel you should use post back trigger.
2- In code behind you should use view state (Property) to store the file name and path then add it to your DB.
3- In your case i think that there is a place you are posting back the page after selecting uploaded file -trace the code-
basically you can save only the extension on the DB, and the image it self on the solution, so you can call it as you said.. you can do something like (code am using for employee images)
If .EmpImagePath <> Nothing Then
FileFullPath = .EmpImagePath
Dim imgURL As String = Convert.ToBase64String(ConvertImageFiletoBytes(.EmpImagePath))
Dim imgSrc As String = String.Format("data:/image/gif;base64,{0}", imgURL)
EmpImg.ImageUrl = imgSrc
Else
If .Gender = "f" Then
EmpImg.ImageUrl = "~/images/no_photo_female.jpg"
Else
EmpImg.ImageUrl = "~/images/nophoto.jpg"
End If
End If
I want to try to change an Image url from four imageButons inside a Datalist, but even I am trying I don't know how
Here is my datalist
<asp:DataList ID="DataList1" runat="server" CellPadding="4"
ForeColor="#333333" OnItemCommand="ItemCommand">
<AlternatingItemStyle BackColor="#2E2E2E" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<ItemStyle BackColor="#151515" />
<ItemTemplate>
<div id="hiden" class="categorry">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table style="margin-left:250px;" width="360px" >
<tr><td colspan="5" height="160px"><asp:Image ID="Image1" imageurl='<%# Eval("Mainfoto") %>' width="360px" height="230px" runat="server" /> </td></tr>
<tr><td width="90px"><asp:ImageButton ID="ImageButton1" imageurl='<%# Eval("Mainfoto") %>' CommandName ="ImageButton1" width="80px" height="70px" runat="server" /> </td>
<td width="90px"><asp:ImageButton ID="ImageButton2" imageurl='<%# Eval("Foto2") %>' CommandName ="ImageButton2" width="80px" height="70px" runat="server" /> </td>
<td width="90px"><asp:ImageButton ID="ImageButton3" imageurl='<%# Eval("Foto3") %>' width="80px" height="70px" runat="server" /> </td>
<td width="90px"><asp:ImageButton ID="ImageButton4" imageurl='<%# Eval("Foto4") %>' width="80px" height="70px" runat="server" /></td></tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ItemTemplate>
<SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:DataList>
and here is my aspx.vb
Protected Sub ItemCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
Dim myListItem As DataListItem = CType(source, DataList).SelectedItem
Dim l As ImageButton = myListItem.FindControl("ImageButton2")
Dim img As Image = myListItem.FindControl("Image1")
If e.CommandName = "ImageButton2" Then
img.ImageUrl = l.ImageUrl
End If
End Sub
hope I am clear enough, and you can help me!
Please make changes in your aspx.vb page as follow :
Protected Sub ItemCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
Dim myListItem As DataListItem = e.Item
Dim l As ImageButton = myListItem.FindControl("ImageButton2")
Dim img As Image = myListItem.FindControl("Image1")
If e.CommandName = "ImageButton2" Then
img.ImageUrl = l.ImageUrl
End If
End Sub
I want to add booth detail into database, after user insert booth alias, select booth type and booth duration, next click submit button and the newly added record will appear in the gridview below the old records.
I know there are something missing in the code but I not sure what is the problem.
The client code:
<%# Page Language="VB" MasterPageFile="~/MasterPageAdmin.master" AutoEventWireup="false" CodeFile="addbooth.aspx.vb" Inherits="addbooth" title="Untitled Page" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="ContentPlaceHolder2" runat="server"
contentplaceholderid="ContentPlaceHolder2">
<table class="style8" cellpadding="3">
<tr>
<td class="style9">Add New Booth</td>
<td> </td>
</tr>
<tr>
<td class="style9"> </td>
<td> </td>
</tr>
<tr>
<td class="style9">Event Title:</td>
<td>
<asp:SqlDataSource ID="SqlDataSourceEventTitle" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" SelectCommand="SELECT DISTINCT [eventID], [eventTitle] FROM [eventinfo]">
</asp:SqlDataSource>
<asp:DropDownList ID="ddlEventTitle" runat="server" DataSourceID="SqlDataSourceEventTitle" DataTextField="eventTitle" DataValueField="eventID" Width="240px" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style9">Booth Alias:</td>
<td>
<asp:TextBox ID="txtBoothAlias" runat="server" Width="235px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style9"> Booth Type:</td>
<td>
<asp:DropDownList ID="ddlBoothType" runat="server" Width="240px" AutoPostBack="True">
<asp:ListItem Value="7">8'x8'</asp:ListItem>
<asp:ListItem Value="10">9'x8'</asp:ListItem>
<asp:ListItem Value="11">12'x50'</asp:ListItem>
<asp:ListItem Value="12">16'x10'</asp:ListItem>
<asp:ListItem Value="13">20'x16'</asp:ListItem>
<asp:ListItem Value="15">32'x10'</asp:ListItem>
<asp:ListItem Value="17">32'x14.5'</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style10" valign="top" colspan="2">Booth Duration:<br />
<font size="2">Tick to activate availability</font></td>
</tr>
<tr>
<td class="style10" valign="top" colspan="2" align="center">
<asp:Panel ID="Panel1" runat="server" Width="328px" Direction="LeftToRight" HorizontalAlign="Center">
<table cellpadding="5" class="style8">
<tr>
<td>
<asp:CheckBox ID="cbWeek1" runat="server" Text="Week 1" TextAlign="Left" OnCheckedChanged="cbWeek1_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek2" runat="server" Text="Week 2" TextAlign="Left" OnCheckedChanged="cbWeek2_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek3" runat="server" Text="Week 3" TextAlign="Left" OnCheckedChanged="cbWeek3_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek4" runat="server" Text="Week 4" TextAlign="Left" OnCheckedChanged="cbWeek4_CheckedChanged" AutoPostBack="true"/>
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="cbWeek5" runat="server" Text="Week 5" TextAlign="Left" OnCheckedChanged="cbWeek5_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek6" runat="server" Text="Week 6" TextAlign="Left" OnCheckedChanged="cbWeek6_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek7" runat="server" Text="Week 7" TextAlign="Left" OnCheckedChanged="cbWeek7_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek8" runat="server" Text="Week 8" TextAlign="Left" OnCheckedChanged="cbWeek8_CheckedChanged" AutoPostBack="true"/>
</td>
</tr>
</table>
</asp:Panel>
<asp:RoundedCornersExtender ID="Panel1_RoundedCornersExtender"runat="server" Enabled="True" TargetControlID="Panel1" BorderColor="CadetBlue" Color="ButtonFace">
</asp:RoundedCornersExtender>
</td>
</tr>
<tr>
<td class="style11">
</td>
<td class="style11">
<asp:Button ID="ButtonAddNewBooth" runat="server" Text="Add New Booth" Height="50px" />
</td>
</tr>
<tr>
<td class="style9"> </td>
<td> </td>
</tr>
<tr>
<td class="style9" colspan="2">
<asp:GridView ID="GridViewBoothAdded" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSourceBoothAdded" Font-Size="Small" ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize="5" Visible="False">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="boothAlias" HeaderText="Booth Alias" SortExpression="boothAlias" />
<asp:BoundField DataField="week1" HeaderText="week1" SortExpression="week1" />
<asp:BoundField DataField="week2" HeaderText="week2" SortExpression="week2" />
<asp:BoundField DataField="week3" HeaderText="week3" SortExpression="week3" />
<asp:BoundField DataField="week4" HeaderText="week4" SortExpression="week4" />
<asp:BoundField DataField="week5" HeaderText="week5" SortExpression="week5" />
<asp:BoundField DataField="week6" HeaderText="week6" SortExpression="week6" />
<asp:BoundField DataField="week7" HeaderText="week7" SortExpression="week7" />
<asp:BoundField DataField="week8" HeaderText="week8" SortExpression="week8" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<EmptyDataTemplate>
No booth record
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="Small" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:RoundedCornersExtender ID="GridViewBoothAdded_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="GridViewBoothAdded">
</asp:RoundedCornersExtender>
<asp:SqlDataSource ID="SqlDataSourceBoothAdded" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [week1], [week2], [week3], [week4], [week5], [week6], [week7], [week8], [eventID], [boothAlias], [eventTitle] FROM [booth_eventinfo] WHERE ([eventID] = #eventID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlEventTitle" Name="eventID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
server code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Threading
Partial Class addbooth
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GridViewBoothAdded.Visible = True
End Sub
Protected Sub ButtonAddNewBooth_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonAddNewBooth.Click
Dim connString As String = ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString
'"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\eventdb.mdf;Integrated Security=True;User Instance=True"
Dim con As SqlConnection = New SqlConnection(connString)
Dim cmdQuery As String = "INSERT INTO booth(eventID,boothAlias,boothType,week1,week2,week3,week4,week5,week6,week7,week8) VALUES (#eventID,#boothAlias,#boothType,#week1,#week2,#week3,#week4,#week5,#week6,#week7,#week8)"
Dim cmd = New SqlCommand(cmdQuery)
cmd.Connection = con
cmd.CommandType = CommandType.Text
con.Open()
cmd.Parameters.AddWithValue("#eventID", ddlEventTitle.SelectedValue)
cmd.Parameters.AddWithValue("#boothAlias", txtBoothAlias.Text)
cmd.Parameters.AddWithValue("#boothType", ddlBoothType.SelectedValue)
If (cbWeek1.Checked = True) Then
cmd.Parameters.AddWithValue("#week1", "1")
Else
cmd.Parameters.AddWithValue("#week1", "0")
End If
If (cbWeek2.Checked = True) Then
cmd.Parameters.AddWithValue("#week2", "1")
Else
cmd.Parameters.AddWithValue("#week2", "0")
End If
If (cbWeek3.Checked = True) Then
cmd.Parameters.AddWithValue("#week3", "1")
Else
cmd.Parameters.AddWithValue("#week3", "0")
End If
If (cbWeek4.Checked = True) Then
cmd.Parameters.AddWithValue("#week4", "1")
Else
cmd.Parameters.AddWithValue("#week4", "0")
End If
If (cbWeek5.Checked = True) Then
cmd.Parameters.AddWithValue("#week5", "1")
Else
cmd.Parameters.AddWithValue("#week5", "0")
End If
If (cbWeek6.Checked = True) Then
cmd.Parameters.AddWithValue("#week6", "1")
Else
cmd.Parameters.AddWithValue("#week6", "0")
End If
If (cbWeek7.Checked = True) Then
cmd.Parameters.AddWithValue("#week7", "1")
Else
cmd.Parameters.AddWithValue("#week7", "0")
End If
If (cbWeek8.Checked = True) Then
cmd.Parameters.AddWithValue("#week8", "1")
Else
cmd.Parameters.AddWithValue("#week8", "0")
End If
GridViewBoothAdded.Visible = True
Can you move you GridView Data Binding Code to code behind file Page_Load Method & call the same code at the end of your ButtonAddNewBooth_Click event. That will serve your purpose.
Link: GridView.DataBind
I see in your ButtonAddNewBooth_Click method you are missing the ExecuteSql() for the sqlcommand and gridview bind code
After adding parameters to cmd add the following two lines one for executing the insert and the other for rebinding the grid
cmd.ExecuteSql()
GridViewBoothAdded.DataBind()