<%@ Control Language="C#" AutoEventWireup="false" Inherits="AJAXControls.BaseControl" %> <% // ViewSelector.ascx // Implementation of the ViewSelector AJAX Control. // Copyright (c) by Matthias Hertel, http://www.mathertel.de // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx // ----- // 21.08.2005 created by Matthias Hertel. // 19.11.2007 using the OpenAjax hub instead of PageProperties %> <script runat="server"> private string _views = String.Empty; // available views private string _eventname = "view"; // the name of the used event public string views { get { return (_views); } set { _views = value; } } // views public string eventname { get { return _eventname; } set { _eventname = value; } } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); base.RegisterBehavior("viewselector"); } // OnPreRender private string GetExpandedViews() { string[] viewList = this._views.Split(';'); for (int n = 0; n < viewList.Length; n++) { string s = viewList[n]; if (s.IndexOf(':') > 0) { string[] s2 = s.Split(':'); Control c = this.Page.FindControl(s2[0]); if (c != null) s2[0] = c.ClientID; viewList[n] = s2[0] + ":" + s2[1]; } else { Control c = this.Page.FindControl(s); if (c != null) viewList[n] = this.Page.FindControl(s).ClientID + ":" + s; } } return (String.Join(";", viewList)); } // GetExpandedViews </script> <%// UI for the control %> <div id="<%=this.ClientID %>" eventname="<%=this.eventname %>" views="<%=this.GetExpandedViews() %>"> <% foreach (string aView in this.views.Split(';')) { string caption, value; int nx = aView.IndexOf(':'); if (nx > 0) { value = aView.Substring(0, nx); caption = aView.Substring(nx + 1); } else { value = aView; caption = aView; } // if %> <%-- using a hyperlink <a href="#<%=value%>" name="selview_<%=value%>" class="passiv"><%=caption%></a> --%> <button view="<%=value%>"><%=caption%></button> <% } // for %> </div> <%// setup then AJAX WebPart connections for the control %> <script type="text/javascript">jcl.LoadBehaviour("<%=this.ClientID %>", jcl.ViewSelectorBehaviour);</script>
This page is part of the http://www.mathertel.de/ web site.
For updates and discussions see http://ajaxaspects.blogspot.com/.