Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

How do I modify this event rule?

Hello again Mates,

I have the control below with default value of uly 08 2011.

<asp:TextBox runat="server" ID="txtEventDate" CssClass="TextBox" Width="157px" Value="Jul 08 2011" />

Open in new window


The date remains July 08 but the only thing that changes is the year.

For instance, next year, which is 2012, the date will be manually changed to July 08, 2012.

Then after this event, we manually change the default value to Oct 11 every year.

The July 08 date restricts who can participate in the event.

The Oct 11 event has no restrictions.

I have the following code which works sort of because the restrictions work when someone who doesn't below in any of the 2 groups listed attempts to register for the event.

                    If txtbef.Text <> "Some04" And txtPre.Text <> "Some7A" Then
                        lblMessage.Text = "You are not eligible to participate in this election."
                    End If

Open in new window


I would like to change the code to this:

                If (txtEventDate.Text = DateTime.Now.ToString("MMM dd yyyy")) Then 'Check which group registrant belongs to.
                
                    If txtbef.Text <> "Some04" And txtbef.Text <> "Some7A" Then 'you cannot participate in this event
                        lblMessage.Text = "You are not eligible to participate in this event."
                    End If
                Else 'Otherwise, change the default date so everyone can participate. The new date is Oct 11 every year
                    txtEventDate.Text = DateTime.Now.ToString("MMM dd yyyy")

                End If

Open in new window


Basically, we would like to avoid manually toggling the date from default value of Jul 08 to Oct 11 and back.

We would like the dates to change automatically AND to allow everyone to participate when the date is NOT Jul 08 but restrict participants to only the 2 groups indicated in the IF statement if date is Jul 8.

None of the changes we desire is working so far.

Any ideas?

Sorry if I am too wordy.

I can clarify if needed.
0
sammySeltzer
Asked:
sammySeltzer
4 Solutions
 
nishant joshiTechnology Development ConsultantCommented:
you can assign value at page load...


txtEventDate.Text=System.Date.Now.toString();
0
 
Ramkisan JagtapLead DeveloperCommented:


Protected Sub Page_Load(sender As Object, e As EventArgs)
      If Not IsPostBack Then
            SetDefaultValue()
      End If
End Sub


Protected Sub SetDefaultValue()
      Dim dtCurrentDate As DateTime = DateTime.Now
      Dim dtFirst As New DateTime(DateTime.Now.Year, 7, 8)
      Dim dtSecond As New DateTime(DateTime.Now.Year, 11, 11)
      If dtFirst < dtCurrentDate Then
            TextBox1.Text = dtFirst.ToShortDateString()
      ElseIf dtFirst < dtCurrentDate AndAlso dtCurrentDate < dtSecond Then
            TextBox1.Text = dtSecond.ToShortDateString()
      Else
            TextBox1.Text = New DateTime((DateTime.Now.Year + 1), 7, 8).ToShortDateString()
      End If
End Sub


Hope this will help you!!!
0
 
Easwaran ParamasivamCommented:
I could not get clear picture on your requirement. However my suggestion is for date selection do not use textbox. Instead you can use calender control and you can customise based on your needs. Please do refer following artilces.

http://www.startvbdotnet.com/controls/datetime.aspx
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/calendar/calendar.aspx 
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sammySeltzerAuthor Commented:
nice, ramkisan, very nice.

It didn't solve any of the problems though.

It still has the July date and the restrictions are still there even after you manually change the date to Oct.
0
 
CodeCruiserCommented:
Try changing to

Protected Sub SetDefaultValue()
      Dim dtCurrentDate As DateTime = DateTime.Now
      Dim dtFirst As New DateTime(DateTime.Now.Year, 7, 8)
      Dim dtSecond As New DateTime(DateTime.Now.Year, 10, 11)
      If dtCurrentDate < dtFirst Then
            TextBox1.Text = dtFirst.ToShortDateString()
      ElseIf dtFirst < dtCurrentDate AndAlso dtCurrentDate < dtSecond Then
            TextBox1.Text = dtSecond.ToShortDateString()
      Else
            TextBox1.Text = New DateTime((DateTime.Now.Year + 1), 7, 8).ToShortDateString()
      End If
End Sub
0
 
sammySeltzerAuthor Commented:
I have already corrected that simple oversight on my code.

Thanks anyway.
0
 
CodeCruiserCommented:
Is the data being compared in correct format given that you are doing a string comparison instead of date comparison?
0
 
sammySeltzerAuthor Commented:
Actually, they lied to me.

Initially, I was told that there is a relationship between eventDate and the conditions applied.

Now, they tell me those conditions are not related to the eventdate.

No matter how accurate the syntax and logic are, it won't work.

Again, I didn't write this code initially.

So, I will just split this point between you guys.

Thanks all and sorry for this inconvenience.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now