1
votes

I have an ajax toolkit calendar extender attached to my textbox and i a trying to fire the OnTextChanged after the date was entered into the textbox.

The thing is i don't want the user to enter data manually so i disabled the textbox but the event won't fire for a disabled text box.

is there anyway around it? i thought about changing to a label but is doesn't have OnTextChanged event.

Thanks

<asp:TableCell CssClass="cssWidth" Width="150px">
            <asp:CalendarExtender ID="CalendarExtender1" PopupButtonID="Image1" runat="server" TargetControlID="TextBoxAddDate" Format="dd/MM/yyyy"></asp:CalendarExtender>
            <asp:TextBox ID="TextBoxAddDate" ReadOnly="true"  CssClass="cssWidth" ToolTip="תאריך הוספה" runat="server" Style="font-size: large;background-color:aliceblue;" AutoPostBack="true" AutoCompleteType="Search" MaxLength="0" TextMode="SingleLine" OnTextChanged="txtSearch_TextChanged" ViewStateMode="Enabled" autocomplete="off" >      
            </asp:TextBox>&nbsp
            <asp:ImageButton runat="Server" ID="Image1"
   ImageUrl="~/Calendar_scheduleHS.png" AlternateText="Click to show calendar" /><br />

        </asp:TableCell>
2

2 Answers

0
votes

Can you use ReadOnly instead of Enabled = false?

UPDATE: Ok, this is the complete solution that worked for me:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
    function dateSelectionChanged(x) {
        debugger;
        javascript: __doPostBack('TextBoxAddDate', '')
    }
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <h2>
        Welcome to ASP.NET!
    </h2>
    <p>
        To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
    </p>
    <p>
        You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
            title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
    </p>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
            <asp:CalendarExtender ID="CalendarExtender1" PopupButtonID="Image1" runat="server" TargetControlID="TextBoxAddDate" Format="dd/MM/yyyy" OnClientDateSelectionChanged="dateSelectionChanged" ></asp:CalendarExtender>
            <asp:TextBox ID="TextBoxAddDate" CssClass="cssWidth" ToolTip="תאריך הוספה" runat="server" Style="font-size: large;background-color:aliceblue;" AutoCompleteType="Search" MaxLength="0" TextMode="SingleLine" OnTextChanged="txtSearch_TextChanged" ViewStateMode="Enabled"> 
            </asp:TextBox>&nbsp
            <asp:ImageButton runat="Server" ID="Image1"
   ImageUrl="~/Calendar_scheduleHS.png" AlternateText="Click to show calendar" /><br />
   </ContentTemplate>
        </asp:UpdatePanel>
</asp:Content>

It seems that the CalendarExtender "steals" away the events from the texbox it uses. Using this approach I managed to fire up the OnTextChanged event and the handler txtSearch_TextChanged gets executed.

0
votes

Did you make the textbox ReadOnly?