wiki
Benvenuto
Guest
, sei in:
<root>
Manual
Manuale IT
Tech
•
Login
• Welcome
Guest
, you are in:
<root>
Manual
Manuale IT
Tech
•
Login
ScrewTurn Wiki
Navigazione (Tech)
¶
Pagina Principale
Pagina Principale (root)
Pagina Casuale
Nuova Pagina
Tutte le Pagine
Categorie
Percorsi di Navigazione
Amministrazione
Gestione File
Registrati
Ricerca wiki
»
Navigation (Tech)
¶
Main Page
Main Page (root)
Random Page
Create a new Page
All Pages
Categories
Navigation Paths
Administration
File Management
Create Account
Search the wiki
»
Back
Moduli dinamici nella pagina Oggi
Modified on 2009/09/30 17:07
by
stefano
Categorized as
Uncategorized
Oggi, la dashboard del sistema, può essere estesa con uteriori moduli a piacimento, che potranno essere integrabili con Tustena Stesso o con altri applicativi. Per creare un nuovo ''modulo'', per prima cosa bisogna aggiungere un file .ascx (il nome è indifferente) nella cartella ''today''. {s:draft} Allego un esempio di codebehind per semplificare le cose: @@ using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using Digita.Tustena.Base; using Digita.Tustena.Core; using Digita.Tustena.Database; using Digita.Tustena.WebControls; namespace Digita.Tustena.today { public partial class MyTodayModule : GUserControl, IToday { public string ResourceText { get { return "moduletxt01"; } } public string ClientId { get { return "mymodule"; } } public bool EnablePaging { get { return true; } } public bool isEnable(string controls) { return controls.Contains(ClientId); } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //Inizializza controllo } } protected override void OnInit(EventArgs e) { base.OnInit(e); MyModuleRepeater.ItemCommand += new RepeaterCommandEventHandler(MyModuleRepeater_ItemCommand); MyModuleRepeater.ItemDataBound += new RepeaterItemEventHandler(MyModuleRepeater_ItemDataBound); } void MyModuleRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) { switch (e.CommandName) { case "DoSomething": // Do Something break; } } void MyModuleRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { switch (e.Item.ItemType) { case ListItemType.Item: case ListItemType.AlternatingItem: // Do Binding break; } } protected override void OnLoad(EventArgs e) { base.OnLoad(e); } } @@ Una volta creato il file .cs, bisogna far ereditare la classe da {{IToday}} e implementare esplicitamente l'interfaccia come nell'esempio. * {{ResourceText}} - Etichetta che comparirà sul titolo del modulo * {{ClientId}} - Un nome/chiave univoco per il riordinamento dei controlli * {{EnablePaging}} - le logiche di visualizzazione del controllo. Verifica se l'utente può vedere quel controllo. Completando le proprietà, il modulo sarà completo e caricato dinamicamente nella scheda. Ci sono alcuni unteripri punti da tenere in considerazione. Come si vede nell'esempio, l'inizializzazione degli eventi nell'OnInit deve essere effettuata dopo il base.OnInit(e) e non prima, altrimenti il compilatore JIT di Tustena non riuscirà a compilare il codice. Qui sotto un esempio funzionante per leggere un feed Rss (in questo caso il feed di Gazzetta.it). Dopo aver instanziato l'oggetto come IToday, andiamo, nel Page_Load a scaricare il feed rss (che è una struttura dati xml) e a popolare il controllo Repeater, nativo di ASP.Net con i dati che abbiamo scaricato. @@ <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Gazzetta.ascx.cs" Inherits="today_Gazzetta" %> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" class="pageTitle" valign="top"> Gazzetta </td> </tr> <tr> <td> <asp:Repeater runat="server" ID="GazzettaFeed"> <HeaderTemplate> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="TableHlip TodayBlackLine"> <tr> <th class="GridTitle"> Titolo Notizia </th> </HeaderTemplate> <ItemTemplate> <tr class="GridItem"> <td> <asp:Literal ID="GazzettaItem" runat="server"></asp:Literal> </td> </tr> </ItemTemplate> <AlternatingItemTemplate> <tr class="GridItemAltern"> <td> <asp:Literal ID="GazzettaItem" runat="server"></asp:Literal> </td> </tr> </AlternatingItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> </td> </tr> </table> @@ @@ using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Digita.Tustena.Base; using System.Net; using System.Xml; using System.IO; public partial class today_Gazzetta : GUserControl, IToday { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { WebClient wc = new WebClient(); byte[] data = wc.DownloadData("http://www.gazzetta.it/rss/Calcio.xml"); MemoryStream ms = new MemoryStream(data); XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(ms); GazzettaFeed.DataSource = xmldoc.SelectNodes("/rss/channel/item[position()<6]"); GazzettaFeed.DataBind(); } } protected override void OnInit(EventArgs e) { base.OnInit(e); GazzettaFeed.ItemDataBound += new RepeaterItemEventHandler(GazzettaFeed_ItemDataBound); } void GazzettaFeed_ItemDataBound(object sender, RepeaterItemEventArgs e) { switch (e.Item.ItemType) { case ListItemType.AlternatingItem: case ListItemType.Item: Literal GazzettaItem = (Literal)e.Item.FindControl("GazzettaItem"); XmlNode xmln = (XmlNode)e.Item.DataItem; GazzettaItem.Text = string.Format("<a target=\"_blank\" href=\"{0}\">{1}</a>", xmln.SelectSingleNode("link").InnerText, xmln.SelectSingleNode("title").InnerText); break; } } #region IToday Membri di public string ClientId { get { return "GazzettaFeed"; } } public bool EnablePaging { get { return false; } } public string ResourceText { get { return "Gazzetta"; } } public bool isEnable(string controls) { return true; } #endregion } @@
Meta Keywords:
Meta Description:
Change Comment: