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

Client-Side access to InPlace controls

3 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Colin
Top achievements
Rank 1
Colin asked on 12 Mar 2012, 04:01 PM
I am attempting to use the method outlined in this article to access controls defined in an InPlace editor, but have thus far not been able to get it to work. What I'd like to do is to use the value from one RadDatePicker to populate another RadDatePicker. The <script> block appears as it should but, when the event handler is called, the variables are both null.

ASP.Net:
<EditItemTemplate>
    <telerik:RadDatePicker runat="server" ID="txtBidDepartDate" Width="90px" DateInput-DateFormat="ddMMMyy" ClientEvents-OnDateSelected="setBidDate"
        SelectedDate='<%# (Eval("departtime").ToString().Length > 0) ? DateTime.Parse(Eval("departtime").ToString()) : DateTime.Now %>' />
    <telerik:RadMaskedTextBox runat="server" ID="txtBidDepartTime" Width="45px" Mask="##:##" Style="text-align:center;"
        Text='<%# (Eval("departtime").ToString().Length > 0) ? DateTime.Parse(Eval("departtime").ToString()).ToString("HH:mm") : "" %>' />
    <asp:RequiredFieldValidator runat="server" ID="validateTxtBidDepartDate" ControlToValidate="txtBidDepartDate" EnableClientScript="true"
        ErrorMessage="Departure Date is required." ValidationGroup="gridBids" Display="Dynamic" />
    <script language="javascript" type="text/javascript">
        departDateObj = $find('<%# Container.FindControl("txtBidDepartDate").ClientID %>');
    </script>
</EditItemTemplate>

JavaScript:
var departDateObj,arriveDateObj;
function setBidDate (sender, args) {
    if (!departDateObj || !arriveDateObj) return false;
 
    if (!arriveDateObj.isEmpty()) return false;
 
    arriveDateObj.set_selectedDate(departDateObj.get_selectedDate());
}

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 15 Mar 2012, 08:38 AM
Hi Colin,

In your setBidDate function the sender is actually the client object of txtBidDepartDate. So you could use it instead of the departDateObj.

I don't see where you have set the arriveDateObj. Make sure that the declaration of arriveDateObj is placed above the assignment. I mean that the code:
var departDateObj,arriveDateObj;
Should be placed above
arriveDateObj = $find(".....");
in your page. Because if you declare it below, it will be null.

Greetings,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Colin
Top achievements
Rank 1
answered on 15 Mar 2012, 03:14 PM
Hi there and thanks for getting back to this.
I changed my layout significantly since posting and have put it into a <FormTemplate>.
To answer your question, I was setting the arriveDateObj in a script block in the EditItemTemplate of the arrive date field. However, I realized that, as JavaScript is evaluated before the HTML is loaded into the DOM, the control would never be found. I changed both script blocks to set these variables (arriveDateObj & departDateObj) as strings representing the ID of the control. This also did not work.

However, I found this article in the documentation while researching something else which solved my issue.
http://www.telerik.com/help/aspnet-ajax/scheduler-customizing-advanced-form-formcreated.html

It may be best to replace what you have in the article I originally linked with what's printed here as this is much more simple and appears to work while the other does not.

Thanks again for getting back to me.
0
Vasil
Telerik team
answered on 19 Mar 2012, 04:16 PM
Hello Colin,

Thank you for your feedback. We will review the resources and improve them if needed.

Greetings,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Colin
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Colin
Top achievements
Rank 1
Share this question
or