Thursday, March 29, 2012

newbie - keeping my object data as page refreshes

Hi all

I have some experience in 'Windows' programming but I am new to Web
programming, I wonder if anyone can help.

I have a middle layer object that brings some data from a database class .
The class reprsents a Callout, has lots of methods and properties and
manages the business logic..

I then have a html page (GUI layer) that creates an instance of a callout,
and from the callout object, it displays some textfields, labour etc plus
some datagrids based on some collections it holds.

Everything works fine until the page refreshes, at which time the object
seems to be destroyed and then recreated.

I want to keep the object alive with its existing data, on the server, and
connect back to it , ie. not create a new object each time. I know I could
use my Callouts WriteDate event to persist the data back to the SQLServer,
and then just re load it, but this isn't what I really want. I would like to
keep the object live until all work has been completed.

I have read a few things about sessions states etc, but don't really know
where to start, and how to make the class persist.

initially I had

public partial class CallOutDetail : System.Web.UI.Page
{
ExistingCallout Currentcallout;
int m_CalloutPK = 0;

protected void Page_Load(object sender, EventArgs e)
{
m_CalloutPK = 1212;
Currentcallout = new ExistingCallout(m_CalloutPK);

I have tried putting the Currentcallout in not postback i.e.

public partial class CallOutDetail : System.Web.UI.Page
{
ExistingCallout Currentcallout;
int m_CalloutPK = 0;

protected void Page_Load(object sender, EventArgs e)
{
m_CalloutPK = 1212;
if (!IsPostBack)
{
// first time
Currentcallout = new ExistingCallout(m_CalloutPK);
SetLabour();
SetMaterials();
}

Any pointers would be welcome

thanks

Andycouple options...
both require that it be serialized

you can place it in the Page's viewstate...

private constant vs_callout="A";

protected CalloutType CurrentCallout{
get{return this.ViewState[vs_callout] as CalloutType;}
set{this.ViewState[vs_callout] = value;}
}

...or place it in the session
}

"AAJ" wrote:

Quote:

Originally Posted by

Hi all
>
I have some experience in 'Windows' programming but I am new to Web
programming, I wonder if anyone can help.
>
I have a middle layer object that brings some data from a database class .
The class reprsents a Callout, has lots of methods and properties and
manages the business logic..
>
I then have a html page (GUI layer) that creates an instance of a callout,
and from the callout object, it displays some textfields, labour etc plus
some datagrids based on some collections it holds.
>
Everything works fine until the page refreshes, at which time the object
seems to be destroyed and then recreated.
>
I want to keep the object alive with its existing data, on the server, and
connect back to it , ie. not create a new object each time. I know I could
use my Callouts WriteDate event to persist the data back to the SQLServer,
and then just re load it, but this isn't what I really want. I would like to
keep the object live until all work has been completed.
>
I have read a few things about sessions states etc, but don't really know
where to start, and how to make the class persist.
>
initially I had
>
public partial class CallOutDetail : System.Web.UI.Page
{
ExistingCallout Currentcallout;
int m_CalloutPK = 0;
>
protected void Page_Load(object sender, EventArgs e)
{
m_CalloutPK = 1212;
Currentcallout = new ExistingCallout(m_CalloutPK);
>
>
I have tried putting the Currentcallout in not postback i.e.
>
public partial class CallOutDetail : System.Web.UI.Page
{
ExistingCallout Currentcallout;
int m_CalloutPK = 0;
>
protected void Page_Load(object sender, EventArgs e)
{
m_CalloutPK = 1212;
if (!IsPostBack)
{
// first time
Currentcallout = new ExistingCallout(m_CalloutPK);
SetLabour();
SetMaterials();
}
>
>
Any pointers would be welcome
>
thanks
>
Andy
>
>
>


thanks David

"David Jessee" <DavidJessee@.discussions.microsoft.comwrote in message
news:CF0F5237-8616-4C4B-9DA9-252BA0946C1D@.microsoft.com...

Quote:

Originally Posted by

couple options...
both require that it be serialized
>
you can place it in the Page's viewstate...
>
private constant vs_callout="A";
>
protected CalloutType CurrentCallout{
get{return this.ViewState[vs_callout] as CalloutType;}
set{this.ViewState[vs_callout] = value;}
}
>
...or place it in the session
}
>
>
>
"AAJ" wrote:
>

Quote:

Originally Posted by

>Hi all
>>
>I have some experience in 'Windows' programming but I am new to Web
>programming, I wonder if anyone can help.
>>
>I have a middle layer object that brings some data from a database class
>.
>The class reprsents a Callout, has lots of methods and properties and
>manages the business logic..
>>
>I then have a html page (GUI layer) that creates an instance of a
>callout,
>and from the callout object, it displays some textfields, labour etc plus
>some datagrids based on some collections it holds.
>>
>Everything works fine until the page refreshes, at which time the object
>seems to be destroyed and then recreated.
>>
>I want to keep the object alive with its existing data, on the server,
>and
>connect back to it , ie. not create a new object each time. I know I
>could
>use my Callouts WriteDate event to persist the data back to the
>SQLServer,
>and then just re load it, but this isn't what I really want. I would like
>to
>keep the object live until all work has been completed.
>>
>I have read a few things about sessions states etc, but don't really know
>where to start, and how to make the class persist.
>>
>initially I had
>>
>public partial class CallOutDetail : System.Web.UI.Page
>{
>ExistingCallout Currentcallout;
>int m_CalloutPK = 0;
>>
>protected void Page_Load(object sender, EventArgs e)
>{
>m_CalloutPK = 1212;
>Currentcallout = new ExistingCallout(m_CalloutPK);
>>
>>
>I have tried putting the Currentcallout in not postback i.e.
>>
>public partial class CallOutDetail : System.Web.UI.Page
>{
>ExistingCallout Currentcallout;
>int m_CalloutPK = 0;
>>
>protected void Page_Load(object sender, EventArgs e)
>{
>m_CalloutPK = 1212;
>if (!IsPostBack)
>{
>// first time
>Currentcallout = new ExistingCallout(m_CalloutPK);
>SetLabour();
>SetMaterials();
>}
>>
>>
>Any pointers would be welcome
>>
>thanks
>>
>Andy
>>
>>
>>

newbie - need early guidance

HI all

I am very new to coding and although I know how things work and what you can do with code and visual design I don't really have experience!

I would like some very basic advise on what coding front end to look into i.e. c++, VB, Web etc.

I am interested in learning to develop a basic system for my cafe that would enable a customer to go through a graphical experience in building their coffee order. I would ideally like to create something that would work well IN the cafe via a touchscreen or on the Internet from their desktop.

Now this is only basic stuff I'm not looking to build a go to market system but just something that applies to my daily life while giving me something new and challenging to look into.

Any guidance would be much appreciated!

Alfo,

I'm glad to hear that you would like to educate yourself in designing / programming / implementing a website.
In my opinion it is this very early stage that is the most important.
It is in this stage that you decide exactly what it is that your site will do and how it will do it.

My advice is to sit down with a pencil and paper and decide on some of the following options:
Will users be required to:
1) Login / Register - if yes
a) before they begin the process of placing an order
b) if they try to place an order
2) How will you accept payment? Cash, credit cards, e-checks, paypal...
3) What are all of the other high level functionalities that you'd like your site to offer?

Regarding what language to use, I much prefer C# (no particular reason, VB.Net is also a great and simple language to use).
It will have no impact on how your site looks to your customers. This is something that is purely up to you.
I do however recommend 2 books (possibly 3 or 4) that will help you greatly in reducing your learning curve and aid you in applying new concepts / ideas in real life situations:
1) Beginning ASP.Net e-commerce in c#. I have the 2005 edition. I'm not sure if there is a newer version or not.
2) Beginning asp.Net in C#.
3) Any beginners SQL book.
4) Any book for HTML / CSS.

If you have any questions or would like any advice let me know.
I used the first 2 books to help me build my first .Net website (https://www.theproductpad.com) and am very greatful for the help that these books gave me.

Good luck,
Michael


thanks

i remember the days when I wrote basic code for ZX Spectrum but now im a little lost!!

I will look into the books.

Aflo

Newbie - need advice on methodology

I am just getting started working on some small, in-house web projects for our work group. These are within the corporate fire-wall, about 10 users or so. Question: The video tutorials on this site show a pretty simple, straightforward way of hooking up a SQl database, master pages, etc. On the other hand, the on-line or PDF tutorials show a much more complex method with what looks to be a lot of hand coding. Leaving aside the standard "It depends on what your're tryingto do" answer for the moment, and given the situation outlined above, is there a reason to go with the all the hand coding as opposed to the drag and drop methods?

I appreciate your opinions and advice!

It depends on what you're trying to do... :)

Drag and drop should be fine, especially for one-off apps that may never be updated. As you gain in your skill set, you'll find where you need to modify your process.

Jeff


I would agree that drag and drop is best to get started as that is what i did. Then once the control is there you can modify it a little more each time. For instance in a gridview maybe format some fields or add hyperlinking.

One caveat is that I had issues with update/insertion working with drag and drop. Also keep in mind that a three tier approrach is best for scalablilty but for under 20 users you can just go straight to the sql. The point of 2.0 and on is ease of development.

Good Luck


It will be much faster to create application if you know how to hand code. However, in my experience, Drag/Drop was a quick and easy way to get started. In about 2-3 weeks, I found my self hand coding since I needed more control over what I was trying to do. Try dragging the controls on to your form, changing settings, then reviewing the code for what you did.

NEWBIE - Multicolumn Listbox populated from SQL statement

Greetings,

I am attempting to generate a multicolumn listbox from a SQL statement in
ASP.NET. Below is my SQL Statement:

SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]

I would like a two column list box with [PACONTNUMBER] on the left and
[PAcontname] on the right. I can do this in MS Access with no problem, but
I do not know to get my datareader info into a multicolumn listbox. I can
do one column of data just fine, but cannot add the second column.

Thank you for your help,

-DaveDeclare the listbox on the .aspx page:
<asp:ListBox runat="server" id="LB" /
Then in code-behind, add the items as you iterate through the repeater:
'Get Repeater 'Data'...
While ( Data.Read() )
LB.Items.Add(New ListItem(Data.Item("Field1") + "-" + Data.Item("Field2"), Data.Item("Field1")))
End While

Note: The above code will have [Field1-Field2] as the text field and [Field1] as the value field for each item in the SqlDataReader

"RockNRoll" wrote:

> Greetings,
> I am attempting to generate a multicolumn listbox from a SQL statement in
> ASP.NET. Below is my SQL Statement:
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no problem, but
> I do not know to get my datareader info into a multicolumn listbox. I can
> do one column of data just fine, but cannot add the second column.
> Thank you for your help,
> -Dave
>
concatenate two columns into one in your sql query

select column1 + column2 as multicolumn
from mytable

then have your datareader use "multicolumn" as your textfield. You'll probably have to do some spacing on top of this if you want the results in actual columns, but that should be easy enough.

Also there is a third party control that does multi-column listbox and some more stuff
http://easylistbox.com/demoQuickStart.aspx#easy

--Michael

"RockNRoll" <daveweber@.yahoo.com> wrote in message news:eJAoYOkeEHA.3916@.TK2MSFTNGP11.phx.gbl...
> Greetings,
>
> I am attempting to generate a multicolumn listbox from a SQL statement in
> ASP.NET. Below is my SQL Statement:
>
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
>
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no problem, but
> I do not know to get my datareader info into a multicolumn listbox. I can
> do one column of data just fine, but cannot add the second column.
>
> Thank you for your help,
>
> -Dave
>

NEWBIE - Multicolumn Listbox populated from SQL statement

Greetings,
I am attempting to generate a multicolumn listbox from a SQL statement in
ASP.NET. Below is my SQL Statement:
SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
I would like a two column list box with [PACONTNUMBER] on the left and
[PAcontname] on the right. I can do this in MS Access with no problem, but
I do not know to get my datareader info into a multicolumn listbox. I can
do one column of data just fine, but cannot add the second column.
Thank you for your help,
-DaveDeclare the listbox on the .aspx page:
<asp:ListBox runat="server" id="LB" />
Then in code-behind, add the items as you iterate through the repeater:
'Get Repeater 'Data'...
While ( Data.Read() )
LB.Items.Add(New ListItem(Data.Item("Field1") + "-" + Data.Item("Field2"), D
ata.Item("Field1")))
End While
Note: The above code will have [Field1-Field2] as the text field and [Field1
] as the value field for each item in the SqlDataReader
"RockNRoll" wrote:

> Greetings,
> I am attempting to generate a multicolumn listbox from a SQL statement in
> ASP.NET. Below is my SQL Statement:
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no problem, but
> I do not know to get my datareader info into a multicolumn listbox. I can
> do one column of data just fine, but cannot add the second column.
> Thank you for your help,
> -Dave
>
>
concatenate two columns into one in your sql query
select column1 + column2 as multicolumn
from mytable
then have your datareader use "multicolumn" as your textfield. You'll =
probably have to do some spacing on top of this if you want the results =
in actual columns, but that should be easy enough.
Also there is a third party control that does multi-column listbox and =
some more stuff
http://easylistbox.com/demoQuickStart.aspx#easy
--Michael
"RockNRoll" <daveweber@.yahoo.com> wrote in message =
news:eJAoYOkeEHA.3916@.TK2MSFTNGP11.phx.gbl...
> Greetings,
>=20
> I am attempting to generate a multicolumn listbox from a SQL statement =
in
> ASP.NET. Below is my SQL Statement:
>=20
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
>=20
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no =
problem, but
> I do not know to get my datareader info into a multicolumn listbox. I =
can
> do one column of data just fine, but cannot add the second column.
>=20
> Thank you for your help,
>=20
> -Dave
>=20
>

newbie - page load not firing

Using asp.net 2.0. I have a page confirm.aspx:
**********************************
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false"
CodeFile="confirm.aspx.vb" Inherits="confirm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
****************************************
*****************
This is my page behind page (confirm.aspx.vb):
Partial Class confirm
Inherits System.Web.UI.Page
Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)
Response.Write("hello")
End Sub
End Class
****************************************
*******
When I confirm.aspx loads in the browser nothing happens. i.e. a blank
page is returned. Shouldn't "hello" be displayed? What am I doing
wrong?Change AutoEventWireup="false" to AutoEventWireup="true" and it should work.
If you're a newbie to .Net from classic asp, note that response.write will
output before all the other content. - i.e. before "<!DOCTYPE.....". But
you'll see that when you run it :)
Jevon
"Steve" <bahram@.iranmania.com> wrote in message
news:1130840485.862653.166360@.g43g2000cwa.googlegroups.com...
> Using asp.net 2.0. I have a page confirm.aspx:
> **********************************
> <%@. Page Language="VB" AutoEventWireup="false"
> CodeFile="confirm.aspx.vb" Inherits="confirm" %>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
> "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> </div>
> </form>
> </body>
> </html>
> ****************************************
*****************
> This is my page behind page (confirm.aspx.vb):
>
> Partial Class confirm
> Inherits System.Web.UI.Page
> Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)
> Response.Write("hello")
> End Sub
> End Class
> ****************************************
*******
> When I confirm.aspx loads in the browser nothing happens. i.e. a blank
> page is returned. Shouldn't "hello" be displayed? What am I doing
> wrong?
>
Set AutoEventWireup to True and try.
"Steve" wrote:

> Using asp.net 2.0. I have a page confirm.aspx:
> **********************************
> <%@. Page Language="VB" AutoEventWireup="false"
> CodeFile="confirm.aspx.vb" Inherits="confirm" %>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
> "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> </div>
> </form>
> </body>
> </html>
> ****************************************
*****************
> This is my page behind page (confirm.aspx.vb):
>
> Partial Class confirm
> Inherits System.Web.UI.Page
> Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)
> Response.Write("hello")
> End Sub
> End Class
> ****************************************
*******
> When I confirm.aspx loads in the browser nothing happens. i.e. a blank
> page is returned. Shouldn't "hello" be displayed? What am I doing
> wrong?
>
Thank you so much for that. I spent more than 2 needless hours this
morning getting frustrated over this. Thank you so much.
So does that mean the Page_Load event can never be captured if the
AutoEventWireup is set to false, or is there a way for the
AutoEventWireup to be set to false and for the Page_Load event to still
be captured?
Yes, manually hook up the handler method with the event:
Sub Page_Load (..., ...) Handles MyBase.Load
...
End Sub
(OR)
' Have the following line in any method/event handler that runs before page
load event.
AddHandler Me.Load, AddressOf Page_Load
"Steve" wrote:

> Thank you so much for that. I spent more than 2 needless hours this
> morning getting frustrated over this. Thank you so much.
> So does that mean the Page_Load event can never be captured if the
> AutoEventWireup is set to false, or is there a way for the
> AutoEventWireup to be set to false and for the Page_Load event to still
> be captured?
>

Newbie - Need to prevent duplicate entries..

Dear All,
Need your help on this issue that I have with asp.net application. I
would really appreciate your help.
I am using Formview to save data into the database, Fields are
(date_from, date_to, time_from, Time_To - All are datetime format and a
roomNumber taken from a value in dropdownlist)
My requirement is simple; I want to prevent other user making
reservation on the specific room with the same dates and times and
within those range.
How will I use sqldatasource insert or any other ways of inserting to
prevent duplicate..
I am sorry for the confusion, i am new to asp.net
Here is the code i am using: --
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false"
CodeFile="insert2.aspx.vb" Inherits="adminaccess_insert2" %>
<%@dotnet.itags.org. Register Assembly="eWorld.UI, Version=2.0.3.2310, Culture=neutral,
PublicKeyToken=24d65337282035f2"
Namespace="eWorld.UI" TagPrefix="ew" %>
<%@dotnet.itags.org. Import Namespace="System.Net.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:RoomReservationConnect
ionString3 %>"
InsertCommand="INSERT INTO [ReservationInfo]
([Date_From], [Date_To], [Time_From], [Time_To], [RoomNo])
VALUES
(@dotnet.itags.org.Date_From, @dotnet.itags.org.Date_To, @dotnet.itags.org.Time_From, @dotnet.itags.org.Time_To, @dotnet.itags.org.RoomNo)" >
<InsertParameters>
<asp:Parameter Name="Date_From" Type="DateTime" />
<asp:Parameter Name="Date_To" Type="DateTime" />
<asp:Parameter Name="Time_From" Type="DateTime" />
<asp:Parameter Name="Time_To" Type="DateTime" />
<asp:Parameter Name="RoomNo" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="Id"
DataSourceID="SqlDataSource1" DefaultMode="Insert">
<InsertItemTemplate>
Date_From:
<br />
<ew:CalendarPopup ID="Date_From" runat="server"
PostedDate=""
SelectedDate='<%# Bind("Date_From") %>'
ImageUrl="~/images/calendar4.jpg"
ControlDisplay="TextBoxImage"
UpperBoundDate="12/31/9999 23:59:59"
Culture="(Default)" Text="Select Date
From">
<ButtonStyle Font-Names="verdana"
Font-Size="8pt"
BackColor="#DEE37F" />
</ew:CalendarPopup>
<br />
<br />
Date_To:
<br />
<ew:CalendarPopup ID="Date_To" runat="server"
PostedDate="" SelectedDate='<%# Bind("Date_To") %>'
ImageUrl="~/images/calendar4.jpg"
ControlDisplay="TextBoxImage" UpperBoundDate="12/31/9999 23:59:59"
Culture="(Default)" Text="Select Date To">
<ButtonStyle Font-Names="verdana"
Font-Size="8pt" BackColor="#DEE37F" />
</ew:CalendarPopup>
<br />
<br />
Time From:
<br />
<ew:TimePicker ID="Time_From" runat="server"
ImageUrl="~/images/calendar3.jpg" NumberOfColumns="3"
LowerBoundTime="12/30/1899 07:00:00"
UpperBoundTime="12/30/1899 23:00:00"
ControlDisplay="TextBoxImage"
PopupLocation="Bottom" PopupWidth="170px"
PopupHeight="178px" EnableViewState="true"
SelectedValue='<%# Bind("Time_From", "{t}")
%>'
PostedTime="7:00 PM"
SelectedTime="12/30/1899 19:00:00"
Text="Select Time Start">
<SelectedTimeStyle BackColor="Khaki"
ForeColor="Black" />
<TimeStyle BackColor="SteelBlue"
ForeColor="White" />
<ButtonStyle BackColor="#DEE37F"
Font-Names="verdana" Font-Size="8pt" />
</ew:TimePicker>
<br />
<br />
Time To:
<br />
<ew:TimePicker ID="Time_To" runat="server"
ImageUrl="~/images/calendar3.jpg"
ControlDisplay="TextBoxImage"
NumberOfColumns="3" LowerBoundTime="11/25/3506 07:00:00"
UpperBoundTime="11/25/3506 23:00:00"
PopupLocation="Bottom" PopupWidth="170px"
PopupHeight="178px" SelectedValue='<%#
Bind("Time_To", "{0:t}") %>' PostedTime="7:00 PM"
SelectedTime="11/25/3506 19:00:28"
Text="Select Time Ends">
<SelectedTimeStyle BackColor="Khaki"
ForeColor="Black" />
<TimeStyle BackColor="SteelBlue"
ForeColor="White" />
<ButtonStyle BackColor="#DEE37F"
Font-Names="verdana" Font-Size="8pt" />
</ew:TimePicker>
<br />
<br />
RoomNo:
<asp:DropDownList ID="RoomNo" runat="server"
DataSourceID="SqlDataSource3" DataTextField="RoomNo"
AppendDataBoundItems="true"
DataValueField="RoomNo" SelectedValue='<%# Bind("RoomNo") %>'>
<asp:ListItem Selected="True">Pls. Select
Your Room No.</asp:ListItem>
</asp:DropDownList><br />
<br />
<%-- Start of DataSource --%>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$
ConnectionStrings:RoomReservationConnect
ionString %>"
SelectCommand="SELECT * FROM
[RoomInfo]"></asp:SqlDataSource>
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
</asp:FormView>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"
Height="18px" Visible="False"></asp:Label>
</form>
</body>
</html>This is really something you want to do in two places. Firstly, design
your UI such that it only offers the option of reserving a room which
is not yet taken. Have you considered using a calendar control of some
kind?
That would probably be more intuitive for use, and has the advantage
that you can only allow certain ranges to be selected.
Secondly, your database should be responsible for maintaining the
integrity of your data. The business rule "A room can be exclusively
reserved for a set of N days, and the time spans may not overlap" can
be handled as a constraint of some kind.
If you try to violate that constraint, your database will throw an
error, and you can handle the resulting exception in your code.
YMPN wrote:

> Dear All,
> Need your help on this issue that I have with asp.net application. I
> would really appreciate your help.
> I am using Formview to save data into the database, Fields are
> (date_from, date_to, time_from, Time_To - All are datetime format and a
> roomNumber taken from a value in dropdownlist)
> My requirement is simple; I want to prevent other user making
> reservation on the specific room with the same dates and times and
> within those range.
> How will I use sqldatasource insert or any other ways of inserting to
> prevent duplicate..
> I am sorry for the confusion, i am new to asp.net
>
> Here is the code i am using: --
> <%@. Page Language="VB" AutoEventWireup="false"
> CodeFile="insert2.aspx.vb" Inherits="adminaccess_insert2" %>
> <%@. Register Assembly="eWorld.UI, Version=2.0.3.2310, Culture=neutral,
> PublicKeyToken=24d65337282035f2"
> Namespace="eWorld.UI" TagPrefix="ew" %>
> <%@. Import Namespace="System.Net.Mail" %>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div />
> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> ConnectionString="<%$
> ConnectionStrings:RoomReservationConnect
ionString3 %>"
> InsertCommand="INSERT INTO [ReservationInfo]
> ([Date_From], [Date_To], [Time_From], [Time_To], [RoomNo])
> VALUES
> (@.Date_From, @.Date_To, @.Time_From, @.Time_To, @.RoomNo)" >
>
> <InsertParameters>
> <asp:Parameter Name="Date_From" Type="DateTime" />
> <asp:Parameter Name="Date_To" Type="DateTime" />
> <asp:Parameter Name="Time_From" Type="DateTime" />
> <asp:Parameter Name="Time_To" Type="DateTime" />
> <asp:Parameter Name="RoomNo" Type="String" />
> </InsertParameters>
> </asp:SqlDataSource>
>
>
> <asp:FormView ID="FormView1" runat="server" DataKeyNames="Id"
> DataSourceID="SqlDataSource1" DefaultMode="Insert">
> <InsertItemTemplate>
> Date_From:
> <br />
>
> <ew:CalendarPopup ID="Date_From" runat="server"
> PostedDate=""
> SelectedDate='<%# Bind("Date_From") %>'
> ImageUrl="~/images/calendar4.jpg"
> ControlDisplay="TextBoxImage"
> UpperBoundDate="12/31/9999 23:59:59"
> Culture="(Default)" Text="Select Date
> From">
> <ButtonStyle Font-Names="verdana"
> Font-Size="8pt"
> BackColor="#DEE37F" />
> </ew:CalendarPopup>
> <br />
> <br />
> Date_To:
> <br />
>
> <ew:CalendarPopup ID="Date_To" runat="server"
> PostedDate="" SelectedDate='<%# Bind("Date_To") %>'
> ImageUrl="~/images/calendar4.jpg"
> ControlDisplay="TextBoxImage" UpperBoundDate="12/31/9999 23:59:59"
> Culture="(Default)" Text="Select Date To">
> <ButtonStyle Font-Names="verdana"
> Font-Size="8pt" BackColor="#DEE37F" />
> </ew:CalendarPopup>
> <br />
> <br />
> Time From:
> <br />
> <ew:TimePicker ID="Time_From" runat="server"
> ImageUrl="~/images/calendar3.jpg" NumberOfColumns="3"
> LowerBoundTime="12/30/1899 07:00:00"
> UpperBoundTime="12/30/1899 23:00:00"
> ControlDisplay="TextBoxImage"
> PopupLocation="Bottom" PopupWidth="170px"
> PopupHeight="178px" EnableViewState="true"
> SelectedValue='<%# Bind("Time_From", "{t}")
> %>'
> PostedTime="7:00 PM"
> SelectedTime="12/30/1899 19:00:00"
> Text="Select Time Start">
> <SelectedTimeStyle BackColor="Khaki"
> ForeColor="Black" />
> <TimeStyle BackColor="SteelBlue"
> ForeColor="White" />
> <ButtonStyle BackColor="#DEE37F"
> Font-Names="verdana" Font-Size="8pt" />
> </ew:TimePicker>
> <br />
> <br />
> Time To:
> <br />
>
> <ew:TimePicker ID="Time_To" runat="server"
> ImageUrl="~/images/calendar3.jpg"
> ControlDisplay="TextBoxImage"
> NumberOfColumns="3" LowerBoundTime="11/25/3506 07:00:00"
> UpperBoundTime="11/25/3506 23:00:00"
> PopupLocation="Bottom" PopupWidth="170px"
> PopupHeight="178px" SelectedValue='<%#
> Bind("Time_To", "{0:t}") %>' PostedTime="7:00 PM"
> SelectedTime="11/25/3506 19:00:28"
> Text="Select Time Ends">
> <SelectedTimeStyle BackColor="Khaki"
> ForeColor="Black" />
> <TimeStyle BackColor="SteelBlue"
> ForeColor="White" />
> <ButtonStyle BackColor="#DEE37F"
> Font-Names="verdana" Font-Size="8pt" />
> </ew:TimePicker>
> <br />
> <br />
> RoomNo:
> <asp:DropDownList ID="RoomNo" runat="server"
> DataSourceID="SqlDataSource3" DataTextField="RoomNo"
> AppendDataBoundItems="true"
> DataValueField="RoomNo" SelectedValue='<%# Bind("RoomNo") %>'>
> <asp:ListItem Selected="True">Pls. Select
> Your Room No.</asp:ListItem>
> </asp:DropDownList><br />
> <br />
> <%-- Start of DataSource --%>
>
> <asp:SqlDataSource ID="SqlDataSource3" runat="server"
> ConnectionString="<%$
> ConnectionStrings:RoomReservationConnect
ionString %>"
> SelectCommand="SELECT * FROM
> [RoomInfo]"></asp:SqlDataSource>
> <asp:LinkButton ID="InsertButton" runat="server"
> CausesValidation="True" CommandName="Insert"
> Text="Insert">
> </asp:LinkButton>
> <asp:LinkButton ID="InsertCancelButton" runat="server"
> CausesValidation="False" CommandName="Cancel"
> Text="Cancel">
> </asp:LinkButton>
>
> </InsertItemTemplate>
> </asp:FormView>
> <br />
> <asp:Label ID="Label1" runat="server" Text="Label"
> Height="18px" Visible="False"></asp:Label>
> </form>
> </body>
> </html>
You're already using a calendar control. Apologies for imbecility. It's
only 5:30 pm and I'm generally not at my best until at least 9:00 :)
Flinky Wisty Pomm wrote:
> This is really something you want to do in two places. Firstly, design
> your UI such that it only offers the option of reserving a room which
> is not yet taken. Have you considered using a calendar control of some
> kind?
> That would probably be more intuitive for use, and has the advantage
> that you can only allow certain ranges to be selected.
> Secondly, your database should be responsible for maintaining the
> integrity of your data. The business rule "A room can be exclusively
> reserved for a set of N days, and the time spans may not overlap" can
> be handled as a constraint of some kind.
> If you try to violate that constraint, your database will throw an
> error, and you can handle the resulting exception in your code.
>
> YMPN wrote:
>
I really appreciate your response FWP. I need all the help that I can..
What you said...
"The business rule "A room can be exclusively
reserved for a set of N days, and the time spans may not overlap" can
be handled as a constraint of some kind.
If you try to violate that constraint, your database will throw an
error, and you can handle the resulting exception in your code.
-- end of qoute --
Can anybody please "translate" this into a working code that I may use
or assist me.
Thanks people...
Flinky Wisty Pomm wrote:
> You're already using a calendar control. Apologies for imbecility. It's
> only 5:30 pm and I'm generally not at my best until at least 9:00 :)
>
> Flinky Wisty Pomm wrote:
>