This is a migrated thread and some comments may be shown as answers.

Preserving value of radMaskedTextBox within FilterTemplate

2 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven Black
Top achievements
Rank 1
Steven Black asked on 26 May 2010, 07:42 PM

Hello,

I have the following FilterTemplate in my grid:

<FilterTemplate> 
    From  
    <telerik:RadMaskedTextBox ID="txtWorkMonthFrom" runat="server" Mask="##/####" Skin="WebBlue" Width="80px" CssClass="CenterText" ClientEvents-OnValueChanged="WorkMonthFromSelected" /> 
    to  
    <telerik:RadMaskedTextBox ID="txtWorkMonthTo" runat="server" Mask="##/####" Skin="WebBlue" Width="80px" CssClass="CenterText" ClientEvents-OnValueChanged="WorkMonthToSelected" /> 
    <telerik:RadScriptBlock ID="rsbWorkMonth" runat="server">  
        <script type="text/javascript">  
            function WorkMonthFromSelected(sender, args) {  
                var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");  
                var ToDate = $find('<%# TryCast(Container, GridItem).FindControl("txtWorkMonthTo").ClientID %>');  
 
                var fromDate = FormatWorkMonth(sender);  
                var toDate = FormatWorkMonth(ToDate);  
 
                if (toDate.indexOf("_") >= 0) {  
                    if (fromDate.indexOf("_") >= 0) {  
                        tableView.filter.clear;  
                    }  
                    else {  
                        tableView.filter("WorkMonth", fromDate, "GreaterThanOrEqualTo");  
                    }  
                }  
                else {  
                    if (fromDate.indexOf("_") >= 0) {  
                        tableView.filter("WorkMonth", toDate, "LessThanOrEqualTo");  
                    }  
                    else {  
                        tableView.filter("WorkMonth", fromDate + " " + toDate, "Between");  
                    }   
                }  
            }  
            function WorkMonthToSelected(sender, args) {  
                var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");  
                var FromDate = $find('<%# TryCast(Container, GridItem).FindControl("txtWorkMonthFrom").ClientID %>');  
 
                var fromDate = FormatWorkMonth(FromDate);  
                var toDate = FormatWorkMonth(sender);  
 
                if (toDate.indexOf("_") >= 0) {  
                    if (fromDate.indexOf("_") >= 0) {  
                        tableView.filter.clear;  
                    }  
                    else {  
                        tableView.filter("WorkMonth", fromDate, "GreaterThanOrEqualTo");  
                    }  
                }  
                else {  
                    if (fromDate.indexOf("_") >= 0) {  
                        tableView.filter("WorkMonth", toDate, "LessThanOrEqualTo");  
                    }  
                    else {  
                        tableView.filter("WorkMonth", fromDate + " " + toDate, "Between");  
                    }  
                }  
            }  
            function FormatWorkMonth(picker) {  
                var date = picker._projectedValue;    
                return date;  
            }  
                                                                                                      
        </script> 
    </telerik:RadScriptBlock> 
</FilterTemplate> 

I modeled this off of the example at http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx.

The difference is that I want to use the radMaskedTextBox for my date fields instead of the radDatePicker control.

When I enter a date into the "From" or "To" date, the grid filters properly.  The problem is that once the grid refreshes, the dates disappears.  So, I can never actually filter with From and To dates at the same time, because as soon as I enter a From date, the grid filters on the From date and then the date disappears.  If I subsequently put a date into the To field, the grid will filter from a null date to the To date (because the From date is no longer there).  Once the grid filters properly using my To date, then it disappears as well.

How can I get my dates to remain in the masked text boxes?

Thanks.

Steve



2 Answers, 1 is accepted

Sort by
0
Steven Black
Top achievements
Rank 1
answered on 29 May 2010, 04:34 AM

Just to let you know, I redesigned my page so that I am no longer using the Filtertemplate, so the answer to this issue is not so important to me.  However, I'm still curious to know how to fix it.

Thanks.
0
Iana Tsolova
Telerik team
answered on 01 Jun 2010, 12:40 PM
Hi Steven,

To persist the from and to date value, you can save them in ViewState, just as it is in the mentioned demo. There you can find that the RadDatePicker controls SelectedDate is get from a public fields defined in the defaultcs.aspx.cs page.

Regards,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Steven Black
Top achievements
Rank 1
Answers by
Steven Black
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or