0

I've a page that displays various drop down menus, one is process and this controls what is displayed in the second - Activities. There is also a time drop down menu. I now have to have a minimum and maximum time for the activities (maximum and minimum is different for all activities) if the users enter a time that is outside the scope an alert box should appear informing the user. Not sure how I do this, any ideas? Im using a stored procedure to populate the drop menus from the database.

Edited by pritaeas: Moved.

3
Contributors
17
Replies
72
Views
4 Years
Discussion Span
Last Post by JorgeM
0
HI,I am not so clear with your question but still i m trying from what i have understood.
First You need have differnt tables for each entity.

1)Actities
2)time
3)Date/Day
4)InformationMaster : Contains all the information such as process,activites and timing.

what you have to do is assign date/day with time slot with assigned/unassigend field. you can set the value based on the information..

eg: date:Monday
`    activites:name of activity`
    Start.Time : 10:00 am
    End.Time : 12:00 pm
    and set assign this time slot and day in DB than...
    Hope it will help you.
0

thanks for the reply, not what im looking for though. I alreadu have my system in place and this particular screen has numerous drop down menus these including process, activity and time. The activity drop down menu gets populated by whatever process is selected. The user can then select the time it took them to carry out this particular activity. Now each activity has a minimum and maximum time the user is allowed to spend carrying it out, however the minimum and maximum time is different for each activity. ive made two columns, one for the min time and one for the max time in my database that holds the activities. However now I need it in my code so that if the user selects a time out of the scope allowed for that particular activity they will be informed by an alert box. Not sure if I'm explaining it very well.

0

Are you trying to validate this client side or server side? If client side, you would have to store the min/max values maybe in various hidden input elements? Then use JavaScript/jQuery to validate the input.

Server side would seem to be easier...when the user selects the time and submits it you would simply select the information from your DB and compare. If its not valid return the appropriate infomation back to the user.

Also, just to be clear...this is ASP or ASP.net?

Edited by JorgeM

0

using server side validation, thats what i thought i would have to do but wasn't sure how i would code it to compare it to the information in the database.

ASP.net, posted in the wrong forum by accident.

0

Well, even "server-side" validation occurs client side. Its just ASP.net's way of providing validation controls.

I'm not sure exactly how you would interface this with the validation controls with regard to comparing with info from a DB. I havent done that personally, but there is information on MSDN on how to do this... a quick search resulted in.. How to: Validate Against Values in a Database for ASP.NET Server Controls

Give it a try...otherwise you could always fall back to this process..

it would require a postback is to allow the user to submit, then on the buttonClick event that you can create in your code behind, just grab the values from the controls and perform a query from your DB, compare values. If they are not acceptable, write the error message back on the page to a label control, or produce the "alert" box using a literal control by assigning the text as the javascript needed to create the alert.

0

Also why not just use some jQuery/Ajax to send the values you want to check to an aspx page, check the results against the DB, then send the info back to the browser. Then take the appropriate action whether you get a true/false as a response for example.

0

HI.
You need to do server side validation through code only. you can assign time into a 24 hours format than you can easily check for max and min time and regarding that slot of time as i told you already you have to block those time slot for the day.. if you want to keep track of assign partlicular time for any activity. you must have one more filed (Assign) in your DB and set datatype as Boolean. so You can Change according to your operations.

0

Its not time slots on a certain day, they select how many minutes it has taken them to carry out the activity.

Thanks JorgeM I will take a look at the link you sent, would use ajax but I haven't alot of experience with it, will research into it though.

0

I know it's a silly question but how can I query the database to compare it with the value in the back end code?

0

You can check it on the server, one way is via Ajax, but you can also allow the user to submit the page and then check. The down side is that this will require a post back. Not a big deal, but the purpose of the client side validation is to stop the post from happening until you have validated the input.

So if you have a submit button, create a button Click event and handle this server side.

0

ok guessing its an if statement I'll need to use. such as if (ddlTime.SelectedValue < databasevalue)

if so how do I get access to the database values so I can compare it?

0

So since you mentioned you had a DB, I had assumed you already created the connections. The actual code you need depends on what type of DB you are connecting to, the tables that hold the data, and your controls on the page that you will access to compare the data.

But at a high level, you need to create a connection, pass a SQL select statement, read the results, and yes you could use conditional statements to compare. Then take an action on the results for example, provide feedback to the user.

If you need help on the connection, there is quite a bit of info online and sample code.

0

Yea I have the connection strings in place but have only been using my database to get the info from it and display it on the page in gridviews etc. have never used it to compare the values selected with what is stored in the database. One thing I'm not allowed to use is an sql select statement, have to use object data sources.

0

I understand. I had assumed that you were accessing your DB from your code-behind, rather than from a control in the aspx page. In any case, I think that someone else may need to provide you with further input.... I dont have any other helpful information for you. Sorry about that...I'll keep an eye out and if I can contribute some more, I'll post the information...

0

It would be easier if I could access the database from the code behind. Thank you, you've been alot of help, I'll keep searching and see if I find anything.

0

If I was accessing the DB from the code behind how would I write it?

0

There are various different ways to write the code to connect to a DB and read data. Here is just one example that connects to an database server (the connection string is stored in the web.config file). The following is written in VB.NET, but you can easily convert it to c#. There is a lot of examples on line as well....

Dim sqlConn As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myDB").ConnectionString)
Dim sqlCmd As New System.Data.SqlClient.SqlCommand
Dim sqlRdr As System.Data.IDataReader
Dim results as Integer
Dim recordID = "// the id of the record you want to search for"

        Try
            sqlConn.Open()
            sqlCmd.Connection = sqlConn
            sqlCmd.CommandText = "Select minValue from table1 where id = '" & recordID & "'"
            sqlRdr = sqlCmd.ExecuteReader
            While sqlRdr.Read()
                results = sqlRdr.GetInt32(0)
            End While
            sqlRdr.Close()
            sqlConn.Close()

        Catch ex As Exception
            ' There was an error, do something...
        End Try

        ' Now that you have the answer in results, do your comparison.  Repeat.

Edited by JorgeM

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.