DevExpress: How to get an instance of the control client side and access its members on the client side?

I have a DateEdit control from DexExpress and you need to get the date value using Javascript. Conceptually, I'm looking for something like this:

var d = $("dpEndDate").GetDate();

Their API reference indicates that .GetDate () is a member, but I just need to know how to get the client instance of the object that contains this element.

+2
source share
3 answers

You must specify the ClientInstanceName property (for ASP.NET WebForms) and the Name property (for ASP.NET MVC) to enable client-side client software elements:

<dx:ASPxDateEdit ... ClientInstanceName="de">
</dx:ASPxDateEdit>

var date = de.GetDate();
+4
source

DevExpress, , , DevExpress 'window.aspxGetControlCollection() ClientID DevExpress, :

window.aspxGetControlCollection().elements[clientID];

, , , , DevExpress, .

ASPxGridView.ClientSideEvents.EndCallback = "function(s,e) { window.aspxGetControlCollection().elements['" + SomeOtherDevExpressControl.ClientID + "'].PerformCallback('callbackArg'); }";

, JS script Client.

JS :

window.ClientControl = function(SomeOtherDevExpressControlClientId)
{
    this.SomeOtherDevExpressControlClientId = SomeOtherDevExpressControlClientId;
    this.SomeOtherDevExpressControl() = function(){ return window.aspxGetControlCollection().elements[this.SomeOtherDevExpressControlClientId]; }
    this.GridEndCallback = function(s,e) { this.SomeOtherDevExpressControl().PerformCallback('callbackArg'); }
}

:

proteced override void Render(HtmlTextWriter writer)
{
    base.Render(writer);
    writer.WriteLine();
    writer.WriteBeginTag("script");
    writer.WriteAttribute("type", "text/javascript");
    writer.Write(">");
    writer.WriteLine("window['" + UserControl.ClientInstanceName+ "'] = new ClientControl('" + SomeOtherDevExpressControl.ClientID + "');");
    writer.WriteEndTag("script");

}

, string ClientInstanceName .

+1

Try:

var d = $("#<%=dpEndDate %>").GetDate();

The reason is that ASP.NET client identifiers are qualified by their naming container in the management tree, so they may end up with something like "ctl1_ct12_ct12_dpEndDate".

You can force ASP.NET 4.0 to not use this hierarchical name, but it is by default.

0
source

All Articles