Solved

Event only fires once

Posted on 2006-11-21
16
197 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

13 Experts available now in Live!

Get 1:1 Help Now