QPR
asked on
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.ImageClickEv entArgs) 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.ImageClickEv entArgs) 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
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.ImageClickEv
CalDate1.Visible = True
End Sub
Protected Sub 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.ImageClickEv
CalDate2.Visible = True
End Sub
Protected Sub CalDate2_SelectionChanged(
txtEndDate.Text = CalDate2.SelectedDate
CalDate2.Visible = False
txtEndDate.Visible = True
End Sub
End Class
ASKER
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
I still don't understand why my imgPin1 event is not firing. The event does nothing except toggle the calendars visibility
ASKER
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.
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.
ASKER
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.
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.
>>>There is if postback code.
Try removing this.
Try removing this.
ASKER
apologies (again) that was a typo in my intial post. That should read there is NO if postback.
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:RequiredFieldValidato r ControlToValidate="txt6Oth er" ID="RequiredFieldValidator 1" runat="server" ErrorMessage="*Required" />
</asp:Panel>
<asp:Panel id="span6" runat="server" visible="false">(please specify) <asp:TextBox runat="server" ID="txt6Other" />
<asp:RequiredFieldValidato
</asp:Panel>
sorry last comment is not belongs here...by mistake i put it here
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....
and use my code in code behind, with this you can track where the actual peroblem occurs....
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.get ElementByI d("txtStar tDate").va lue) < Date.parse(document.getEle mentById(" txtEndDate ").value))
{
document.getElementById("l blerror"). visibility = 'visible'
return false;
}
return true;
}
u can call this function on ur button click by writing below line in page_load..
btnLoadChart.Attributes.Ad d("onclick ", "return checkdate();")
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.get
{
document.getElementById("l
return false;
}
return true;
}
u can call this function on ur button click by writing below line in page_load..
btnLoadChart.Attributes.Ad
ASKER
Thanks, can you help with this bit
btnLoadChart.Attributes.Ad d("onclick ", "return checkdate();")
I put it here but get errors
<body onload="Button1.Attributes .Add("oncl ick", "return checkdate();")">
error = name and attribute must be separated by an equals sign
btnLoadChart.Attributes.Ad
I put it here but get errors
<body onload="Button1.Attributes
error = name and attribute must be separated by an equals sign
ASKER
sorry! I realised that was code behind *blush*
ASKER
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?
Making the calendar visible is causing a postback which is firing validation.
How can I prevent this?
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.ImageClickEv
Calendar1.Visible = True
End Sub
Private Sub ImageButton2_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEv
Calendar2.Visible = True
End Sub
Private Sub 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
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(Te
TextBox1.Visible = False
TextBox2.Visible = False
Button1.Visible = False
''''''''''''''''''''''''''
End If
End Sub