访问clinet端的用户控件属性

时间:2015-05-25 07:30:29

标签: asp.net properties user-controls

我有一个用户控件 - FilterPanel.ascx ,在 QuickSearch.aspx 上使用了两次

<dx:ASPxRoundPanel ID="filterPanel" ClientInstanceName="filterPanel" runat="server" ShowCollapseButton="True" CssClass="contentPanel" CornerRadius="0">
 <ContentPaddings Padding="0px" />
 <HeaderStyle CssClass="contentPanelHeader" ImageSpacing="0px" ForeColor="#FFFFFF" BackColor="#5A81B3" />
 <PanelCollection>
 <dx:PanelContent>
          <dx:ASPxTextBox runat="server" ID="txtdxKeyword" Width="139px" Height="18px" Visible="True" NullText="Keyword">
           <ClientSideEvents LostFocus="function(s,e) { FilterCheckbox_CheckChanged(s,'FILTER:TEXTBOX'); }" GotFocus="function(s,e) { CheckMode('FILTER'); }"></ClientSideEvents>
           </dx:ASPxTextBox>
   </dx:PanelContent>
   </PanelCollection>
   </dx:ASPxRoundPanel>

FilterPanel.ascx.cs 获得了一个属性模式

        public SearchResultsGridUpdateMode Mode { set; get; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Mode == SearchResultsGridUpdateMode.Filter)
            {
                Header = "Filter";
                hfMode.Value = "Filter";
            }
            else if (Mode == SearchResultsGridUpdateMode.Exclusion)
            {
                Header = "Exclusion";
                hfMode.Value = "Exclusion";
            }
            else
                Header = string.Empty;

            filterPanel.HeaderText = Header;
        }

枚举 -

 public enum SearchResultsGridUpdateMode
    {
        Filter,
        Exclusion
    }

QuickSearch.aspx

<asp:Content ID="QuickSearchLeftContent" runat="server" ContentPlaceHolderID="SearchMasterLeftContentPlaceHolder">
    <table style="border-collapse: collapse; margin: 0 auto;">
        <tr>
            <td>
                <uc1:FilterPanel ID="ucFilterPanel" runat="server" Mode="Filter"/>
            </td>
        </tr>
        <tr>
            <td>
                <uc1:FilterPanel ID="ucExclusionPanel" runat="server" Mode="Exclusion"/>
            </td>
        </tr>
    </table>
</asp:Content>

QuickSearch.aspx 中,我将模式的用户控件( FilterPanel.ascx )值设置为&#39; 过滤&#39;或&#39; 排除&#39;

现在我想在 FilterPanel.ascx

中的任何客户端事件中为ASPxTextBox传递模式的值

例如 FilterPanel.ascx 上的控件 TextBox

GotFocus =&#34; function(s,e){CheckFilterMode( MODE VALUE );}

可以在客户端发送UserControl属性值吗? 请帮忙,

1 个答案:

答案 0 :(得分:1)

尝试这样的事情。

    public SearchResultsGridUpdateMode Mode 
    {
        set
        {
            this.txtdxKeyword.ClientSideEvents.GotFocus = "function(s,e) { CheckMode('" + value.ToString() + "'); }";
            Header = value.ToString;
            hfMode.Value = value.ToString;
        }

        get; 
    }