Event only fires once

I have 2 image buttons that when clicked change their respective calendars to visible.
A date is selected. The calendar reverts to hidden, the date populates a textbox and that text box becomes visible.
Then the user does this same process on the 2nd image button.
These represent a start date and an end date. I have a compare validator that ensures end date is > start date.
All of the above works fine.
However if end date > start date and the user is prompted to repick their dates... clicking on the image buttons will not show the calendars again. Nothing happens. There is if postback code.
Here is my code behind. Can anyone see why the events are only fired/handled the first times?

Partial Class _InputRound
    Inherits System.Web.UI.Page

    Protected Sub imgPin1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgPin1.Click
        CalDate1.Visible = True
    End Sub

    Protected Sub CalDate1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CalDate1.SelectionChanged
        txtStartDate.Text = CalDate1.SelectedDate
        CalDate1.Visible = False
        txtStartDate.Visible = True
    End Sub

    Protected Sub imgPin2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgPin2.Click
        CalDate2.Visible = True
    End Sub

    Protected Sub CalDate2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CalDate2.SelectionChanged
        txtEndDate.Text = CalDate2.SelectedDate
        CalDate2.Visible = False
        txtEndDate.Visible = True
    End Sub

End Class
LVL 29
QPRAsked:
Who is Participating?
 
Computer101Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0
 
sandip132Commented:
Here is you code:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Visible = False
    End Sub

    Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Calendar1.Visible = True
    End Sub

    Private Sub ImageButton2_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
        Calendar2.Visible = True
    End Sub

    Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
        TextBox1.Text = Calendar1.SelectedDate
        TextBox1.Visible = True
        If (TextBox1.Text <> "" And TextBox2.Text <> "") Then
            Button1.Visible = True
        End If
    End Sub

    Private Sub Calendar2_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar2.SelectionChanged
        TextBox2.Text = Calendar2.SelectedDate
        TextBox2.Visible = True
        If (TextBox1.Text <> "" And TextBox2.Text <> "") Then
            Button1.Visible = True
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If (DateTime.Compare(CDate(TextBox1.Text), CDate(TextBox2.Text)) > 0) Then
            TextBox1.Visible = False
            TextBox2.Visible = False
            Button1.Visible = False
           ''''''''''''''''''''''''''''''''''''''''''''''''Please select dates again.
        End If


    End Sub
0
 
QPRAuthor Commented:
Is this replacing my existing date compare validator control?
I still don't understand why my imgPin1 event is not firing. The event does nothing except toggle the calendars visibility
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
QPRAuthor Commented:
Why am I setting the the buttons visibility to false
Also, when I try your way....
I click on the imagebutton to bring up the calendar and validation fires even though I haven't submitted yet.
0
 
QPRAuthor Commented:
apologies ignore the line below - it does this regardless if I use yours or my version...


Also, when I try your way....
I click on the imagebutton to bring up the calendar and validation fires even though I haven't submitted yet.
0
 
sandip132Commented:
>>>There is if postback code.

Try removing this.
0
 
QPRAuthor Commented:
apologies (again) that was a typo in my intial post. That should read there is NO if postback.
0
 
badalpatelCommented:
u just have to add one more requiredfieldvalidator in ur panel span6..i think that will do it..and if u want to do this with javascript then tell me i will help u out...

 <asp:Panel id="span6" runat="server" visible="false">(please specify) <asp:TextBox runat="server" ID="txt6Other" />
                     <asp:RequiredFieldValidator ControlToValidate="txt6Other" ID="RequiredFieldValidator1" runat="server" ErrorMessage="*Required" />
                     </asp:Panel>
0
 
badalpatelCommented:
sorry last comment is not belongs here...by mistake i put it here
0
 
sandip132Commented:
Please create one new application, put 2 imagebuttons, 2 calenders, 2 textboxes abd a button with default(IDs).

and use my code in code behind, with this you can track where the actual peroblem occurs....
0
 
badalpatelCommented:
HIi QPR

yes while the comparevalidator is true the page wil not postback and calendar control need the postback..thats why the page is not showing there..
what u can do is to put a javascript to end ur problem..u put one label instead of compare validator and make it visible true when the startdate<enddate or any of ur condition...this will check ur textbox value when u click on button while submitting ur form..

i m showing code of javascript

function checkdate()
{
if(Date.parse(document.getElementById("txtStartDate").value) < Date.parse(document.getElementById("txtEndDate").value))
            {
                document.getElementById("lblerror").visibility = 'visible'
               return false;
            }
   return true;
}

u can call this function on ur button click by writing below line in page_load..
btnLoadChart.Attributes.Add("onclick", "return checkdate();")
0
 
QPRAuthor Commented:
Thanks, can you help with this bit
btnLoadChart.Attributes.Add("onclick", "return checkdate();")

I put it here but get errors
<body onload="Button1.Attributes.Add("onclick", "return checkdate();")">

error = name and attribute must be separated by an equals sign
0
 
QPRAuthor Commented:
sorry! I realised that was code behind *blush*
0
 
QPRAuthor Commented:
Still no good, now when I click the image to toggle the calendars visibility I get 1 less validation error (compare) but I still get the other 2... startdate required and end date required. I don't want to hassle the user with these messages until they hit the submit button.
Making the calendar visible is causing a postback which is firing validation.

How can I prevent this?
0
 
QPRAuthor Commented:
solved!
I just needed to set the "causes validation" property on the image button to false.
Now when it postsback to toggle the calendars visibility it doesn't check the form values.
AND it let's me retoggle the calendar following validation
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.