.NET komponenty
Kategorie: Skola

na project -> add/ new project -> class library

na class -> add reference reference System.Web
do class pridat using System.Web.UI;

na projekt -> property pages, references --> zalozka project --> pridat class


build --> toolbox


Page.Request.Browser - objekt Http... ovbsahujici vlastnosti prohlizece

writer.Write(Page.Request.Browser.Browser); // jmeno prohlizece atd


using System.Web.UI.WebControls; !!! pro label button apod

pri psani pouzivat TAB -> generuje automaticky




using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web;
using System.Web.UI.WebControls;

namespace ClassLibrary1
{
public class Class1 : Control, INamingContainer
{
Label label1;
Button btn;
string name;

// tady vytvorime label a button atd
protected override void CreateChildControls()
{
label1 = new Label();
label1.Text = "ahoj";
Controls.Add(label1);
btn = new Button();
btn.Text = "send";
Controls.Add(btn);
btn.Click += new EventHandler(btn_Click);
base.CreateChildControls();
}

void btn_Click(object sender, EventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}


public string Name
{
get { return ViewState["name"].ToString();} // ulozime viewstate
set { ViewState["name"] = value;
name = value;
} // a zase nacteme, abychom i po kliknuti meli name
}

protected override void Render(HtmlTextWriter writer)
{
/* HttpBrowserCapabilities prohlizec = Page.Request.Browser;
writer.Write("agent je {0}", prohlizec.Browser); // pomoci string format vypiseme typ prohlizece
writer.RenderBeginTag("br"); // odradkovani
writer.RenderEndTag();*/
writer.Write(Name); // vypiseme viewstate
base.Render(writer); // a vyredrujeme cely nas control
}
}
}


22.10.2007 13:58:51