Session State C# Declaration Passing textbox.Text - c#

Ok I have a fairly simple issue I want to define some session state variables
So far in my code behind in C# for an aspx page I have the following type of declaration working fine in my index.aspx.cs file.
Session[Constants.firstName] = "Jordan";
or
Session[Constants.firstName] = 123;
I want to grab the Text from the index.aspx Textboxes though instead like so.
Session[Constants.firstName] = txtb_FName.Text;
The problem is that changing this to the variable txtb_FName.Text does not work and when I debug it shows the local variable is being filled with "" not the input from my Textbox.
The whole CODE trail looks like this;
index.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="ProjectPhase02.index" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Project Phase 02</title>
<link id="Link1" href="main.css" rel="stylesheet" runat="server" />
</head>
<body>
<form id="form1" runat="server" method="get" action="accountCreationConfirmation.aspx">
<div>
<asp:Label CssClass="accountFormLable" runat="server" Text="First Name: "></asp:Label>
<asp:TextBox ID="txtb_FName" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Last Name: "></asp:Label>
<asp:TextBox ID="txtb_LName" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="User Name: "></asp:Label>
<asp:TextBox ID="txtb_UName" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Password: "></asp:Label>
<asp:TextBox ID="txtb_Password" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Address: "></asp:Label>
<asp:TextBox ID="txtb_Address" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Email: "></asp:Label>
<asp:TextBox ID="txtb_Email" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Phone: "></asp:Label>
<asp:TextBox ID="txtb_Phone" runat="server"></asp:TextBox>
<br />
<asp:Button ID="submitButton" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>
index.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ProjectPhase02
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session[Constants.firstName] = txtb_FName.Text;
Session[Constants.lastName] = txtb_LName.Text;
Session[Constants.userName] = txtb_UName.Text;
Session[Constants.password] = txtb_Password.Text;
Session[Constants.address] = txtb_Address.Text;
Session[Constants.email] = txtb_Email.Text;
Session[Constants.phoneNumber] = txtb_Phone;
}
}
}
Constants.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ProjectPhase02
{
public static class Constants
{
public static string firstName = "thatFName";
public static string lastName = "thatLName";
public static string userName = "thatUName";
public static string password = "thatPass";
public static string address = "thatAddress";
public static string email = "thatEmail";
public static string phoneNumber = "thatPNumber";
}
}
accountCreationConfirmation.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ProjectPhase02
{
public partial class accountCreationConfirmation : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string fN = (string) Session[Constants.firstName];
string lN = (string) Session[Constants.lastName];
string uN = (string) Session[Constants.userName];
string pW = (string) Session[Constants.password];
string ad = (string) Session[Constants.address];
string em = (string) Session[Constants.email];
string pN = (string) Session[Constants.phoneNumber];
lbl_FName.Text = fN;
lbl_LName.Text = lN;
lbl_UName.Text = uN;
lbl_Password.Text = pW;
lbl_Address.Text = ad;
lbl_Email.Text = em;
lbl_Phone.Text = pN;
}
}
}
accountCreationConfirmation.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="accountCreationConfirmation.aspx.cs" Inherits="ProjectPhase02.accountCreationConfirmation" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Project Phase 02</title>
<link id="Link1" href="main.css" rel="stylesheet" runat="server" />
</head>
<body>
<form id="form1" runat="server" >
<div>
<asp:Label CssClass="accountFormLable" runat="server" Text="First Name: "></asp:Label>
<asp:Label ID="lbl_FName" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Last Name: "></asp:Label>
<asp:Label ID="lbl_LName" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="User Name: "></asp:Label>
<asp:Label ID="lbl_UName" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Password: "></asp:Label>
<asp:Label ID="lbl_Password" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Address: "></asp:Label>
<asp:Label ID="lbl_Address" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Email: "></asp:Label>
<asp:Label ID="lbl_Email" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Phone: "></asp:Label>
<asp:Label ID="lbl_Phone" runat="server"></asp:Label>
<br />
</div>
</form>
</body>
</html>
main.css
.accountFormLable {
width: 100px;
float: left;
display: block;
clear: left;
}

Related

Validation Summary Not Displaying (C# ASP.NET 4.5)

I have a an ASP.NET web form that needs to valid user input. However, upon entering invalid-user input the validation summary is not displaying. The weird thing was that it was working for a period of time and then now it doesn't show at all. Here is my code.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Registration.aspx.cs" Inherits="Registration" %>
<!DOCTYPE html>
<html>
<head>
<title>Coding Club Registration</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Coding Club Registration Form</h1>
<form runat="server" defaultbutton="Submit">
<div>
<asp:Label ID="NameLabel" runat="server" Text="Your Name:" AssociatedControlID="NameTextBox" AccessKey="N"></asp:Label>
<asp:TextBox ID="NameTextBox" runat="server" Columns="30" MaxLength="30"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="NameTextBox" CssClass="error" ErrorMessage="Name Required"><span>*</span></asp:RequiredFieldValidator>
<br /><br />
<asp:Label ID="EmailLabel" runat="server" Text="Your Email:" AssociatedControlID="EmailTextBox" AccessKey="N"></asp:Label>
<asp:TextBox ID="EmailTextBox" runat="server" Columns="30" MaxLength="30"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="EmailTextBox" CssClass="error" Display="Dynamic" ErrorMessage="Email Required"><span>*</span></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="EmailTextBox" CssClass="error" Display="Dynamic" ErrorMessage="Invalid Email" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
<br /><br />
<asp:Label ID="PhoneLabel" runat="server" Text="Your Phone:" AssociatedControlID="PhoneTextBox" AccessKey="N"></asp:Label>
<asp:TextBox ID="PhoneTextBox" runat="server" Columns="30" MaxLength="30"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="PhoneTextBox" CssClass="error" Display="Dynamic" ErrorMessage="Phone Required"><span>*</span></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="PhoneTextBox" CssClass="error" Display="Dynamic" ErrorMessage="Invalid Phone" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">*</asp:RegularExpressionValidator>
<br /><br />
<asp:Button ID="Submit" runat="server" Text="Submit Form" AccessKey="S" onclick="SubmitButton_Click" />
<asp:Button ID="Clear" runat="server" Text="Clear Form" AccessKey="C" onclick="ClearButton_Click" CausesValidation="False" />
<br /><br />
<div class="container">
<asp:Label ID="Result" runat="server" Text="" Visible="false"></asp:Label>
</div>
</div>
<asp:ValidationSummary ID="Errors" runat="server" ForeColor="Red" />
</form>
</body>
</html>
protected void SubmitButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
// Add form results to result label
string newText = "<h3>The Information Entered</h3>";
newText += "<p>Name: " + NameTextBox.Text + "</p>";
newText += "<p>Email: " + EmailTextBox.Text + "</p>";
newText += "<p>Phone: " + PhoneTextBox.Text + "</p>";
Result.Text = newText;
// Set result lable visibility to true
Result.Visible = true;
}
}
protected void ClearButton_Click(object sender, EventArgs e)
{
// Clear form fields
NameTextBox.Text = "";
EmailTextBox.Text = "";
PhoneTextBox.Text = "";
// Remove result visibility
Result.Visible = false;
// Errors.Visible = false;
}
}
Any help would be appreciated!

How to make the information in a dropdownlist change

So i want to make a drop down list that displays new information if you select different radio buttons.
And im struggling.For Example if radio button 1 is selected the information in dropbox must change to popcorn and sweets.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
margin-left: 18px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server" OnCheckedChanged="RadioButton1_CheckedChanged" Text="Day" />
</div>
<asp:RadioButton ID="RadioButton2" runat="server" Text="Night" />
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Cream Soda</asp:ListItem>
<asp:ListItem>coke</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" CssClass="auto-style1" Width="139px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Seat No:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="140px"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Height="20px" Text="Add Choice" />
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
</form>
</body>
</html>
You must define autopostback="true" on the RadioButton, and then you need to handle the selected value in the codebehind, and re-fill the drop-down with a new item-list.
Page-Cycle will be like this
Page_Load
RadioButton2_Changed
Page_LoadComplete
So make sure you either set the new content in RadioButton2_Changed, or in Page_LoadComplete. If you try to do it in Page_Load, you'll have the old value of radiobutton, and that will not work well ...
You can try the following steps to show the correspond information when you click the radio button.
First, you need to change your html file into the following:
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server" OnCheckedChanged="RadioButton1_CheckedChanged" Text="Day" GroupName="Ra" AutoPostBack="true" />
</div>
<asp:RadioButton ID="RadioButton2" runat="server" Text="Night" OnCheckedChanged="RadioButton2_CheckedChanged" GroupName="Ra" AutoPostBack="true"/>
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" CssClass="auto-style1" Width="139px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Seat No:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="140px"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Height="20px" Text="Add Choice" />
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
</form>
</body>
Second, you need to call the RadioButton1_CheckedChanged event and RadioButton2_CheckedChanged event to to add the listitem.
ListItem list1 = new ListItem("popcorn");
ListItem list2 = new ListItem("sweets");
ListItem list3 = new ListItem("Cream Soda");
ListItem list4 = new ListItem("coke");
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if(RadioButton1.Checked==true)
{
if (!DropDownList1.Items.Contains(list1) && !DropDownList1.Items.Contains(list2))
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add(list1);
DropDownList1.Items.Add(list2);
}
}
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton2.Checked == true)
{
if (!DropDownList1.Items.Contains(list3) && !DropDownList1.Items.Contains(list4))
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add(list3);
DropDownList1.Items.Add(list4);
}
}
}
Result:

how can i bind data to one gridview by load page and click to a object inside gridview

that is html code for main page for social network .
i use a gridview by templet element that post and image bind from database by loading page but i want comnt for each post binded by click to buttin show comment
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:GridView ID="gvPosts" runat="server"
AutoGenerateColumns="False" Height="46px" Width="45px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<fieldset class="color">
<fieldset>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("username") %>'></asp:Label>
<div class="crope_main" id="zoom">
<asp:Image ID="ImageUSER" runat="server" Width="50px" Height="50px" ImageUrl='<%# Eval("picture") %>' />
</div>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("biografy") %>'></asp:Label>
<fieldset>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("date_post") %>'></asp:Label>
</fieldset>
</fieldset>
<asp:Image ID="imgeposts" runat="server" Height="200px" Width="400px" ImageUrl='<%# Eval("pic_book") %>' Style="margin-top: 43px; margin-right: 2px;" />
<fieldset>
<asp:Label ID="Label1" runat="server" Text="NameBOOk:"></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("name_book") %>' />
</fieldset>
<fieldset>
<asp:Label ID="Label3" runat="server" Text="Writer:"></asp:Label>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("wrieter") %>'></asp:Label>
</fieldset>
</fieldset>
<div>
<asp:Label ID="lblidpost" runat="server" Text='<%# Eval("id_post_FK") %>' Visible="false" />
<asp:Label ID="lbluser_id_email" runat="server" Text='<%# Eval("id_user_fk") %>' Visible="false" />
<asp:Label ID="lbllike" runat="server" Text='<%# Eval("SUM_LIKE") %>' />
</div>
<asp:TextBox ID="TxtSummery" runat="server" Text='<%# Eval("summery") %>' TextMode="MultiLine" Width="390px" Height="34px" Enabled="false"></asp:TextBox>
</div>
<div>
<asp:Button ID="btn_showComment" runat="server" Text="show comment" OnClick="btn_showComment_Click" />
</div>
<div>
<asp:TextBox runat="server" TextMode="MultiLine" Width="391px" ></asp:TextBox>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:ImageField>
</asp:ImageField>
</Columns>
</asp:GridView>
<asp:Image ID="imgLoader" runat="server" ImageUrl="~/images/loading.gif" />
</div>
</fieldset>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class pages_main : System.Web.UI.Page
{
string m,j, Btnn, ofline;
int k = 1, record = 0;
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{ BindData(); }
}
protected void BindData()
{
DataSet.usersDataTable oUserDataTable =
new DataSet.usersDataTable();
DataSetTableAdapters.usersTableAdapter oUserTableAdapter =
new DataSetTableAdapters.usersTableAdapter();
oUserTableAdapter.FillBy_userID(oUserDataTable, (Int64)Session["UserID"]);
DataSet.usersRow userrow = oUserDataTable[0];
//////////////////////////////////////////////////
DataSet.postDataTable postDatatabale = new DataSet.postDataTable();
DataSetTableAdapters.postTableAdapter postTabeladabtor = new DataSetTableAdapters.postTableAdapter();
postTabeladabtor.FillBy_showPost(postDatatabale, Session["email"].ToString());
///////////////////////////////////////////////////
//////////////////////////////////////////////////
if (postDatatabale.Count != 0)
{
DataSet.postRow postrow = postDatatabale[0];
string imageProfile = "~/profile/" + Session["Username"] + ".jpg";
gvPosts.DataSource = postDatatabale;
gvPosts.DataBind();
for (int i = 0; i < gvPosts.Rows.Count; i++)
{
ImageButton h = ((ImageButton)gvPosts.Rows[i].FindControl("imaglike"));
ImageButton h1 = ((ImageButton)gvPosts.Rows[i].FindControl("imageDisLike"));
//h.ID = "delbtn" + gvPosts.Rows[i];
// h1.ID = "imbtn" + gvPosts.Rows[i];
// h.ImageUrl = ("../Images/heart.png");
//h1.ImageUrl = ("../Images/Broken_Heart.png");
}
}
}
protected void btn_showComment_Click(object sender, EventArgs e)
{
GridViewRow gridViewRow = (GridViewRow)(sender as Control).Parent.Parent;
int index = gridViewRow.RowIndex;
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
m = ((Label)this.gvPosts.Rows[gvr.RowIndex].FindControl("lblidpost")).Text;
j = ((Label)this.gvPosts.Rows[gvr.RowIndex].FindControl("lbluser_id_email")).Text;
DataSet.commentDataTable comment = new DataSet.commentDataTable();
DataSetTableAdapters.commentTableAdapter ta_comment = new DataSetTableAdapters.commentTableAdapter();
ta_comment.FillBy_comment_post(comment, j, int.Parse(m));
DataSet.commentRow row = comment[index];
if(row.text_comment!="")
{
Response.Write("hello");
}
}
}
You have to use the RowCommand event:
<asp:Button ID="btn_showComment" runat="server" Text="show comment" CommandName="ShowComment" />
And then from the code beside:
protected void gvPosts_RowCommand(object source, RepeaterCommandEventArgs)
{
if (e.CommandName == "ShowComment")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = ContactsGridView.Rows[index];
}
}
Reference: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand(v=vs.110).aspx

null reference exception on page redirect

I'm getting a null reference exception on singleKingButton.Checked = true; in the page load event. If I comment it out then I still get one on the next line setting the date. The odd thing is the page loads fine it's when I hit the submit button that I get the error. Thanks in advance!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace garrettPenfieldUnit4
{
public partial class Default : System.Web.UI.Page
{
Reservation newReservation = new Reservation();
//Load events, automatically inserts todays date and selects the single king radio button
protected void Page_Load(object sender, EventArgs e)
{
UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
singleKingButton.Checked = true;
arrivalDateBox.Text = DateTime.Today.ToShortDateString();
}
//When submit button is clicked show the two confirmation labels.
protected void submitButton_Click(object sender, EventArgs e)
{
newReservation.ArrivalDate = Convert.ToDateTime(arrivalDateBox.Text);
newReservation.DepartureDate = Convert.ToDateTime(departureDateBox.Text);
newReservation.NoOfPeople = peopleDropDown.SelectedIndex;
newReservation.SpecialRequests = specialRequestsBox.Text;
newReservation.FirstName = firstNameBox.Text;
newReservation.LastName = lastNameBox.Text;
newReservation.Email = addressBox.Text;
newReservation.Phone = telephoneNumberBox.Text;
newReservation.PreferredMethod = contactDropDown.SelectedIndex.ToString();
if (singleKingButton.Checked)
{
newReservation.BedType = "Single King";
}
if (twoQueensButton.Checked)
{
newReservation.BedType = "Two Queens";
}
if (singleQueenButton.Checked)
{
newReservation.BedType = "Single Queen";
}
Session["Reservation"] = newReservation;
Response.Redirect("~/ConfirmationPage.aspx");
}
//When the clear button is clicked clear the form and reset fields to their default values
protected void clearButton_Click(object sender, EventArgs e)
{
arrivalDateBox.Text = DateTime.Today.ToShortDateString();
departureDateBox.Text = String.Empty;
peopleDropDown.SelectedIndex = 0;
singleKingButton.Checked = true;
twoQueensButton.Checked = false;
singleQueenButton.Checked = false;
specialRequestsBox.Text = String.Empty;
firstNameBox.Text = String.Empty;
lastNameBox.Text = String.Empty;
addressBox.Text = String.Empty;
telephoneNumberBox.Text = String.Empty;
contactDropDown.SelectedIndex = 0;
}
}
}
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="garrettPenfieldUnit4.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Royal Inn and Suites</title>
<link href="Content/bootstrap.css" rel="stylesheet" />
<link href="Content/Main.css" rel="stylesheet" />
<script src="Scripts/jquery-1.9.1.min.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
</head>
<body>
<form id="form1" runat="server" defaultbutton="submitButton" defaultfocus="arrivalDateBox">
<div class="container">
<div id="page-header">
<h1 style="color: blue;">Royal Inn and Suites</h1>
<p style="color: red; font-style: italic;">
Where you're always treated like royalty
</div>
<h3 style="color: blue;">Reservation Request</h3>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red" />
</div>
<div id="form-group">
<h4>Request Data</h4>
<div>
Arrival Date<asp:RequiredFieldValidator ID="arrivalDateBoxValidator" runat="server" ErrorMessage="Arrival date is required"
ControlToValidate="arrivalDateBox" ForeColor="Red" Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="arrivalDateValidator" runat="server" ErrorMessage="Arrival date must be before departure date."
ControlToValidate="arrivalDateBox" ControlToCompare="departureDateBox" Display="Dynamic"
Operator="DataTypeCheck" Type="Date" ForeColor="red">*</asp:CompareValidator>
</div>
<div>
<asp:TextBox ID="arrivalDateBox" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div>Departure Date</div>
<div>
<asp:TextBox ID="departureDateBox" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="departureDateBoxValidator" runat="server" ErrorMessage="Departure date is required"
ControlToValidate="departureDateBox" ForeColor="Red" Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="departureDateCompareValidator" runat="server" ErrorMessage="Departure date must be after arrival date"
ControlToValidate="departureDateBox" ForeColor="Red" ControlToCompare="arrivalDateBox" Display="Dynamic" Operator="GreaterThan"
Type="Date">*</asp:CompareValidator>
</div>
<div>Number of People</div>
<div>
<asp:DropDownList ID="peopleDropDown" runat="server" CssClass="form-control">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:DropDownList>
</div>
<div>
<div>
Bed Type
<asp:RadioButton ID="singleKingButton" runat="server" Text="King" GroupName="bedType" />
<asp:RadioButton ID="twoQueensButton" runat="server" Text="Two Queens" GroupName="bedType" />
<asp:RadioButton ID="singleQueenButton" runat="server" Text="Single Queen" GroupName="bedType" />
</div>
</div>
<h3>Special Requests</h3>
<div>
<asp:TextBox ID="specialRequestsBox" runat="server" TextMode="MultiLine" CssClass="form-control"></asp:TextBox>
</div>
<h3>Contact Information</h3>
<div>First Name</div>
<asp:TextBox ID="firstNameBox" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="firstNameBoxValidator" runat="server" ErrorMessage="First name is required"
ControlToValidate="firstNameBox" ForeColor="Red">*</asp:RequiredFieldValidator>
<div>Last Name</div>
<asp:TextBox ID="lastNameBox" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="lastNameBoxValidator" runat="server" ErrorMessage="Last name is required"
ControlToValidate="lastNameBox" ForeColor="Red">*</asp:RequiredFieldValidator>
<div>E-mail Address</div>
<asp:TextBox ID="addressBox" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="addressBoxValidator" runat="server" ErrorMessage="Email address is required"
ControlToValidate="addressBox" ForeColor="Red" Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="addressBoxExpressionValidator1" runat="server" ErrorMessage="Invalid Email"
ControlToValidate="addressBox" ForeColor="Red" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
<div>Telephone Number</div>
<asp:TextBox ID="telephoneNumberBox" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="telephoneNumberBoxValidator" runat="server" ErrorMessage="Telephone Number is required"
ControlToValidate="telephoneNumberBox" ForeColor="Red" Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="telephoneExpressionValidator" runat="server"
ErrorMessage="Invalid phone number" ControlToValidate="telephoneNumberBox" ForeColor="red" Display="Dynamic" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">*</asp:RegularExpressionValidator>
<div>Preferred Method of Contact</div>
<asp:DropDownList ID="contactDropDown" runat="server" CssClass="form-control">
<asp:ListItem>E-mail</asp:ListItem>
<asp:ListItem>Telephone</asp:ListItem>
</asp:DropDownList>
<div>
<asp:Button ID="submitButton" class="btn btn-primary btn-space" runat="server" Text="Submit" OnClick="submitButton_Click" />
<asp:Button ID="clearButton" class="btn btn-primary btn-space" runat="server" Text="Clear" OnClick="clearButton_Click" BackColor="#33CC33" />
</div>
<div>
<asp:Label ID="submitLabel1" runat="server" Text="Thank you for your Request." Visible="False" ForeColor="Green"></asp:Label>
</div>
<div>
<asp:Label ID="submitLabel2" runat="server" EnableViewState="False" Text="We will get back to you within 24 hours." Visible="False" ForeColor="Green"></asp:Label>
</div>
</div>
</form>
</body>
</html>
One of these all properties is receiving 'NULL' and at the time of inserting this values in database your table structure is not allowing 'NULL'.
So make sure that if you want to store 'NULL' in table then allow NULL in table structure (Table design).
You can check it using "line by line execution" of your code (using break point).

Uploading images with a progress bar in asp.net c#

I am writting a program (web site) which uploads images on the server,displays them and saves them in a folder. I want to add a progress bar which will be connected to the image's file size while it is being filled.Here is my Default.aspx file
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
<br />
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
<output id="images"></output>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvPhotos" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField ="Text" HeaderText="filename" />
<asp:ImageField DataImageUrlField="Value" ControlStyle-Height="250" ControlStyle-Width="250" HeaderText="Photo" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
Loading....<br />
<br />
</ProgressTemplate>
</asp:UpdateProgress>
</div>
<p>
<asp:Label ID="lblSuccess" runat="server"></asp:Label>
</p>
</form>
</body>
</html>
This is Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
List<ListItem> sia = new List<ListItem>();
if(FileUpload1.HasFiles)
{
foreach(var file in FileUpload1.PostedFiles)
{ string[] fileName = Directory.GetFiles(Server.MapPath("~/Images/"));
file.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"), file.FileName));
Response.Write(file.FileName + " - " + file.ContentLength + " Bytes. <br />");
sia.Add(new ListItem(file.FileName, "~/Images/" + file.FileName));
}
lblSuccess.Text = string.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count);
}
gvPhotos.DataSource = sia;
gvPhotos.DataBind();
}
}
Please help me in inserting a jquery bar in my Default.aspx. Thank you in advance

Categories

Resources