Solved

Event only fires once

Posted on 2006-11-21
16
198 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:QPR
  • 8
  • 3
  • 3
  • +1
16 Comments
 
LVL 12

Expert Comment

by:sandip132
ID: 17992453
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
 
LVL 29

Author Comment

by:QPR
ID: 17992535
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
 
LVL 29

Author Comment

by:QPR
ID: 17992569
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
 
LVL 29

Author Comment

by:QPR
ID: 17992599
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
 
LVL 12

Expert Comment

by:sandip132
ID: 17992715
>>>There is if postback code.

Try removing this.
0
 
LVL 29

Author Comment

by:QPR
ID: 17992800
apologies (again) that was a typo in my intial post. That should read there is NO if postback.
0
 
LVL 6

Expert Comment

by:badalpatel
ID: 17993245
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:badalpatel
ID: 17993250
sorry last comment is not belongs here...by mistake i put it here
0
 
LVL 12

Expert Comment

by:sandip132
ID: 17993319
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
 
LVL 6

Expert Comment

by:badalpatel
ID: 17993337
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
 
LVL 29

Author Comment

by:QPR
ID: 17999517
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
 
LVL 29

Author Comment

by:QPR
ID: 17999529
sorry! I realised that was code behind *blush*
0
 
LVL 29

Author Comment

by:QPR
ID: 17999594
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
 
LVL 29

Author Comment

by:QPR
ID: 18000809
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18222692
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now