protected void savebtn_Click(object sender, EventArgs e)
    {
        if (template == null)
        {
            Guid TemplateId = new Guid(HttpContext.Current.Request.QueryString["TemplateId"]);
            Guid EventId = new Guid(HttpContext.Current.Request.QueryString["EventId"]);
            Guid ModuleId = new Guid(HttpContext.Current.Request.QueryString["ModuleId"]);
            manager = new DataManager();
            template = manager.GetTemplate(EventId, TemplateId, ModuleId);
        }
        template.Subject = this.txtSubject.Text;
        template.Sender = this.txtSender.Text;
        template.SenderAddress = this.txtSenderAdd.Text;
        template.Content = this.txtContent.Text;
        this.manager.SaveTemplate(template);

        string script = "function GetRadWindow()";
        script += "{";
        script += " var oWindow = null;";
        script += " if (window.radWindow) oWindow = window.radWindow;";
        script += " else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;";
        script += " return oWindow;";
        script += "}";

        script += "function OK_Clicked()";
        script += "{";
        script += " var oWindow = GetRadWindow();";
        script += " oWindow.Close(true);";
        script += "}";
        script += "OK_Clicked();";
        HttpContext.Current.Session.Add("EventId", new Guid(HttpContext.Current.Request.QueryString["EventId"]));
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "returnokscript", script, true);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Guid TemplateId = new Guid(HttpContext.Current.Request.QueryString["TemplateId"]);
        Guid EventId = new Guid(HttpContext.Current.Request.QueryString["EventId"]);
        Guid ModuleId = new Guid(HttpContext.Current.Request.QueryString["ModuleId"]);

        if (!IsPostBack)
        {
            if (this.manager == null)
                this.manager = new DataManager();

            template = manager.GetTemplate(EventId, TemplateId, ModuleId);
            if (template != null)
            {
                this.txtSubject.Text = template.Subject;
                this.txtSender.Text = template.Sender;
                this.txtSenderAdd.Text = template.SenderAddress;
                this.txtContent.Text = template.Content;
                this.legenedsRep.DataSource = DataManager._Legends.GetAvailabelLegends();
                this.legenedsRep.ItemDataBound += new RepeaterItemEventHandler(legenedsRep_ItemDataBound);
                this.legenedsRep.DataBind();
            }
        }
    }