0

I have a usercontrol and inside the html for the usercontrol, I have the following definition for a Popup control which I am trying to access from my aspx page via javascript.

<dx:ASPxPopupControl ID="MainASPxPopupControl"
                ClientInstanceName="MainASPxClientPopupControl"
                runat="server"
                HeaderStyle-HorizontalAlign="Left"
                RenderMode="Lightweight"
                AutoUpdatePosition="true"
                PopupHorizontalAlign="WindowCenter"
                PopupVerticalAlign="WindowCenter"
                OnInit="MainASPxPopupControl_Init">

In the code-behind for the usercontrol, I have the following property so my aspx page will be able to access it:

public static object MainASPxClientPopupControl { get; set; }

In the code behind of my aspx page in the Page_load event, I have the following. This prevents the error: "The Controls collection cannot be modified because the control contains code blocks”</p>

Page.Header.DataBind();

In my JS, instead of using:

<%=

which will cause the above error, I am using:

<%#

which is a databinding expression and need for the snippet in my page_load method.

Here is where the real problem lies... I have code in a JS function on my aspx page that gets hit, but always displays that the object is null. I am simply trying to get an instance of the object (the popup control in the usercontrol) where I can use it accordingly.

var cntrl = document.getElementById('<%# BMCIS.Source.Controls.ManagerSwipe.MainASPxClientPopupControl %>');
cntrl.Show();

During debugging, the runtime code is displayed as follows:

var cntrl = document.getElementById('');

The error message given is: "Unable to get property 'Show' of undefined or null reference" which obviously means (checked during debugging) that the variable "cntrl" is null and cannot get the instance of the popup control in the user control.

How can I successfully get an instance of this control???

4

2 に答える 2

0

Control.ClientID プロパティの使用を検討してください

.NET オブジェクトは JS 側では取得できず、JS DOM 環境では機能しません。ClientID を使用して JS で DOM オブジェクトを取得し、表示する任意の種類の JS メソッド ( http://www.randomsnippets など) を使用する必要があります。 com/2008/02/12/how-to-hide-and-show-your-div/

于 2013-10-15T21:08:56.113 に答える
0

実際には、「サーバー コントロール名.ClientInstanceName」を取得し、データバインディング式「<%#」を使用しているため、ページ ヘッダーのコントロールの Load イベントにデータバインドを配置する必要がありました。

これがコードスニペットです。var swipe = eval('<%# MyManagerSwipe.ClientInstanceName %>');

于 2013-10-16T20:08:53.210 に答える