locked
ajaxToolkitCalender Update itselef even if I delete the info from the box RRS feed

  • Question

  • User796871965 posted

    Hi

    I have 

    <asp:Label ID="litlblFrom" Font-Bold="true" CssClass="LabelFilterSelection" runat="server" Text="<%$ Resources:GlobalResources, LabelFrom %>" />
    <asp:TextBox CssClass="DateTextFilterSelection" runat="server" ID="FromDateTextBox"></asp:TextBox>
    <img class="ImageFixedSize" id="FromCalendarButton" src="../../images/calendar.jpg"
    alt="" />
    <ajaxToolkit:CalendarExtender ID="FromCalendarExtender" runat="server" TargetControlID="FromDateTextBox"
    PopupButtonID="FromCalendarButton">
    </ajaxToolkit:CalendarExtender>

    <asp:Label ID="litlblTo" CssClass="LabelFilterSelectionNoWidth" runat="server" Font-Bold="true" Text="<%$ Resources:GlobalResources, LabelTo %>" />
    <asp:TextBox CssClass="DateTextFilterSelection" runat="server" ID="ToDateTextBox" ></asp:TextBox>
    <img class="ImageFixedSize" id="ToCalendarButton" src="../../images/calendar.jpg"
    alt="" />
    <ajaxToolkit:CalendarExtender ID="ToCalendarExtender" runat="server" TargetControlID="ToDateTextBox"
    PopupButtonID="ToCalendarButton">
    </ajaxToolkit:CalendarExtender>

    and I have four Validators :

    <asp:CompareValidator runat="server" ID="CheckFromDate" ControlToValidate="FromDateTextBox"
    Operator="DataTypeCheck" SetFocusOnError="true" Display="Dynamic" CssClass="ErrorLabel"
    ErrorMessage="<%$ Resources:GlobalResources, StartDateNotValid %>" Type="Date"></asp:CompareValidator>
    <br />
    <asp:CompareValidator ID="CheckToDate" runat="server" ControlToValidate="ToDateTextBox"
    ControlToCompare="FromDateTextBox" SetFocusOnError="true" Display="Dynamic" Operator="GreaterThan"
    CssClass="ErrorLabel" ErrorMessage="<%$ Resources:GlobalResources, EndDateNotValid %>"
    Type="Date"></asp:CompareValidator>
    <asp:RequiredFieldValidator ID="RequiredFieldValidatorFrom" runat="server" CssClass="ErrorLabel"
    ControlToValidate="FromDateTextBox" ValidationGroup="FormSubmit" Display="Dynamic" ErrorMessage="<%$ Resources:GlobalResources, StartDateRequired %>">
    </asp:RequiredFieldValidator>
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidatorTo" runat="server" CssClass="ErrorLabel"
    ControlToValidate="ToDateTextBox" Display="Dynamic" ErrorMessage="<%$ Resources:GlobalResources, EndDateRequired %>">
    </asp:RequiredFieldValidator>

    and this is my Button asp code and also I have 2 combobox that when the last one is selected, it will check if the To and the From texts are full also and then activate the button

    btnStartExportRPT.Enable="true";

    <asp:Button ID="btnStartExportRPT" EnableTheming="true" CssClass="ButtonFilterSelectionL"
    Text="<%$ Resources:GlobalResources, cmdStartExecute %>" runat="server" />

    my problem is that when I remove the date, for instance from the FromDateTextBox I want to deactivate my button instantly but

      1- when I delete the From text (for instance) it shows me the error but it does not trigger any event to be able to control the button from the C# based on this error

      2- each time I empty the To or From box as soon as I change sth from the comboboxes it reloads a default date and I do not want it to be reload

    Thanks for the help in advance

    Wednesday, June 10, 2015 9:39 AM

Answers

  • User1724605321 posted

    Hi laly,

    Thanks for your post.

    LaLyXX

    1- when I delete the From text (for instance) it shows me the error but it does not trigger any event to be able to control the button from the C# based on this error

    It won’t trigger any event because you haven’t registered any event to listen to the text change.

    You could add “OnTextChanged” event to textbox:

    <asp:TextBox CssClass="DateTextFilterSelection" AutoPostBack="true" runat="server" ID="FromDateTextBox" OnTextChanged="FromDateTextBox_TextChanged" >
    </asp:TextBox>

    Code behind:

            protected void FromDateTextBox_TextChanged(object sender, EventArgs e)
            {
                if (string.IsNullOrEmpty( this.FromDateTextBox.Text))
                {
                    btnStartExportRPT.Enabled=false;
                }
            }

    Then when textbox is empty , button will be disabled.

    LaLyXX

    2- each time I empty the To or From box as soon as I change sth from the comboboxes it reloads a default date and I do not want it to be reload

    Your combobox’s select event causes a postback,the page reload.

    <asp:UpdatePanel runat="server">
                <ContentTemplate>
                //your code here
         </ContentTemplate>
    </asp:UpdatePanel>

    For more information about update panel ,please refer to the links below:
    https://msdn.microsoft.com/en-us/library/bb399001(v=vs.140).aspx .
    http://www.asp.net/web-forms/overview/older-versions-getting-started/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers .


    Best Regards,
    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2015 1:10 AM