Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

i have two textbox like to_date and from_date with two ajax calendar. i have third textox to calculate total days between two selected dates. i use this page in scriptmanager with updatepanel.

so, problem is that when i use firefox browser and select from date and then to date it does not get postback and not calculate the total days in third textbox.

so, what can i do ?

it works perfact in google chrome but not in IE or Firefox... i just write the code into to_date event.
 protected void txt_to_date_TextChanged(object sender, EventArgs e)
    {
        IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-GB", true);
        DateTime from_date = DateTime.ParseExact(txt_from_date.Text, "dd/MM/yyyy", theCultureInfo);
        DateTime to = DateTime.ParseExact(txt_to_date.Text, "dd/MM/yyyy", theCultureInfo);
        int result = DateTime.Compare(to, from_date);
        if (result < 0)
        {
            txt_to_date.Text = "";
            txt_to_date.Focus();
            lbl_msg.Visible = true;
            lbl_msg.ForeColor = System.Drawing.Color.Red;
            lbl_msg.Text = "To date is not Less than your From Date";
            txt_total_days.Text = "";
        }
        else if (result == 0)
        {
            txt_total_days.Text = "1";
            Panel1.Visible = true;
        }
        else 
        {
            Panel2.Visible = false;
            Panel1.Visible = false;
            txt_total_days.Text = ((to - from_date).TotalDays + 1).ToString();
        }
    }

the ASPX code like :


<asp:ScriptManager ID="s1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<table border="1" width="100%">

<tr>
<td align="center" colspan="2">
    <asp:Label ID="Label1" runat="server" Text="Online Leave Application" 
        Font-Size="Large" ForeColor="Black" Font-Bold="True"></asp:Label>
</td>
</tr>

<tr>
<td align="left">
    <asp:Label ID="Label2" runat="server" Text="Date" Font-Size="Medium" 
        ForeColor="Black"></asp:Label>
</td>
<td align="left">
    <asp:TextBox ID="txt_date" runat="server" Columns="20" 
        Font-Size="Medium" Enabled="False"></asp:TextBox>
</td>
</tr>



<tr>
<td align="left">
    <asp:Label ID="Label5" runat="server" Text="From Date" Font-Size="Medium" 
        ForeColor="Black"></asp:Label>
</td>
<td align="left">
    <asp:TextBox ID="txt_from_date" runat="server" Columns="20"  
        ValidationGroup="temp" Font-Size="Medium" Enabled="False"></asp:TextBox>
      <asp:ImageButton ID="ImageButton1" runat="server" Height="25px" 
            ImageUrl="~/Images1/calendar.jpg" Width="30px" ValidationGroup="temp" 
        onclick="ImageButton1_Click1"/>
            
        <ajax:CalendarExtender ID="CalendarExtender1"  runat="server" PopupButtonID="ImageButton1" TargetControlID="txt_from_date"  OnClientDateSelectionChanged="chkdate" Format="dd/MM/yyyy">
        </ajax:CalendarExtender>
       
        
</td>
</tr>


<tr>
<td align="left">
    <asp:Label ID="Label6" runat="server" Text="To Date" Font-Size="Medium" 
        ForeColor="Black"></asp:Label>
</td>
<td align="left">
    <asp:TextBox ID="txt_to_date" runat="server" Columns="20"  
        ValidationGroup="temp1" Font-Size="Medium" Enabled="False" 
        EnableTheming="True" ontextchanged="txt_to_date_TextChanged" 
        AutoPostBack="True"></asp:TextBox>
      <asp:ImageButton ID="ImageButton2" runat="server" Height="25px" 
            ImageUrl="~/Images1/calendar.jpg" Width="30px" ValidationGroup="temp1" 
        onclick="ImageButton2_Click" />
           
        <ajax:CalendarExtender ID="CalendarExtender2"  runat="server" PopupButtonID="ImageButton2" TargetControlID="txt_to_date"  OnClientDateSelectionChanged="chkdate" Format="dd/MM/yyyy">
        </ajax:CalendarExtender>
      <asp:CustomValidator ID="scdt1" runat="server" OnServerValidate="chkdate1" ErrorMessage="To date not less than From date" ControlToValidate="txt_from_date"></asp:CustomValidator>
</td>
</tr>
<tr>
<td align="left">
     <asp:Label ID="Label9" runat="server" Text="Total Leave(s) Day(s)" Font-Size="Medium" 
        ForeColor="Black"></asp:Label>
</td>
<td align="left">
    <asp:TextBox ID="txt_total_days" runat="server" Text="0" Enabled="false" 
        Font-Size="Medium" ForeColor="Black"></asp:TextBox>
</td>
</tr>

<tr>

<td align="center" colspan="2">
<asp:Panel ID="Panel1" runat="server" Visible="false"> 
     <asp:RadioButton ID="rd_full" runat="server" Text="Full Day Leave" 
         GroupName="a" Checked="true" AutoPostBack="True" Font-Size="Medium" 
         ForeColor="Black" oncheckedchanged="rd_full_CheckedChanged" />
     <asp:RadioButton ID="rd_half" runat="server" Text="Half Day Leave" 
         GroupName="a" AutoPostBack="True" Font-Size="Medium" ForeColor="Black" 
         oncheckedchanged="rd_half_CheckedChanged" />
         </asp:Panel>
</td>
</tr>



<tr>

<td align="center" colspan="2">
<asp:Panel ID="Panel2" runat="server" Visible="false">
     <asp:RadioButton ID="rd_first_half" runat="server" Text="First Half" 
         GroupName="b" Checked="true"  Font-Size="Medium" 
         ForeColor="Black" oncheckedchanged="rd_first_half_CheckedChanged" />
     <asp:RadioButton ID="rd_second_half" runat="server" Text="Second Half" 
         GroupName="b"  Font-Size="Medium" ForeColor="Black" />
         </asp:Panel>
</td>

</tr>

<tr>
<td align="left">
    <asp:Label ID="Label8" runat="server" Text="Enter Reason" Font-Size="Medium" 
        ForeColor="Black"></asp:Label>
</td>
<td align="left">
    <asp:TextBox ID="txt_reason" runat="server" TextMode="MultiLine" 
        Font-Size="Large" ForeColor="Black" Height="150px" Width="450px" 
        ></asp:TextBox>
</td>
</tr>

<tr>
<td align="left">
    <asp:Label ID="Label7" runat="server" Text="Report To Whom" Font-Size="Medium" 
        ForeColor="Black"></asp:Label>
</td>
<td align="left">
    <asp:TextBox ID="TextBox1" runat="server" Columns="45" Font-Size="Medium" 
        ForeColor="Black" Enabled="False"></asp:TextBox>
</td>
</tr>

<tr>
<td align="center" colspan="2">
    <asp:Button ID="Button1" runat="server" Text="Submit" Font-Size="Large" 
        ForeColor="Black" Width="30%" OnClientClick="return validate()" onclick="Button1_Click1" 
         />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="up1">
<ProgressTemplate>
<div align="center" style="color: #000000">
     <img src="images/progress.gif" align="middle" height="20" /> Please Wait ...
     </div>
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
<tr>
<td align="center" colspan="2">
    <asp:Label ID="lbl_msg" runat="server" Font-Size="Medium" ForeColor="Green" 
        Visible="False"></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>

please help me....

if i remove the Enable=false to the both textbox, it works fine in FIREFOX but i want to not editable that textbox by the user.

Thanks and Regards....
Mitesh
Posted
Updated 13-Jul-12 18:43pm
v5
Comments
willempipi 13-Jul-12 8:21am    
Can you supply some code?
Karthik Harve 13-Jul-12 8:24am    
I guess, the ajax calender will not post back by itself. so how are you posting back the page? are you using __doPostBack method?
Sandeep Mewara 13-Jul-12 10:31am    
ASPX code snippet?
AmitGajjar 14-Jul-12 0:47am    
Can you do the same code using javascript ? it seems like problem with Disabled text box. but as you said it works fine for Google chrome its again another question. but if possible the the same code through javascript.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900