Click here to Skip to main content
       

ASP.NET

 
Questionlinq connection in asp.net PinmemberJonBrynjar8-Dec-12 3:58 
AnswerRe: linq connection in asp.net Pinmember@AmitGajjar11-Dec-12 7:00 
QuestionChange root path PinmvpJohn Simmons / outlaw programmer8-Dec-12 3:40 
AnswerRe: Change root path PinmemberRichard Deeming10-Dec-12 1:35 
GeneralRe: Change root path PinmvpJohn Simmons / outlaw programmer10-Dec-12 1:42 
AnswerRe: Change root path Pinmember@AmitGajjar11-Dec-12 7:10 
QuestionUpdating the column using entity framework Pinmemberindian1437-Dec-12 12:46 
Questionasp.NET composite control cannot raise an event Pinmembermichal.cerbak7-Dec-12 4:50 
I have problem with Composite Control in ASP.NET. Im making a classlibrary with this content \/ , but the problem is, that i cannot see it in toolbox, but i register it in web.config file, compile it and add a reference to it. And another problem is that my composite control cannot raise an event. 
 

<pre>// composite control
namespace MyCompControl
{
    public class CreateArticleEventArgs : EventArgs
    {
        public bool IsValid { get; private set; }
        public Article article { get; private set; }
 
        public CreateArticleEventArgs(bool IsValid, Article article)
        {
            this.IsValid = IsValid;
            this.article = article;
        }
 
        public CreateArticleEventArgs(bool IsValid)
        {
            this.IsValid = IsValid;
            this.article = null;
        }
    }
 
    [
    AspNetHostingPermission(SecurityAction.Demand,
        Level = AspNetHostingPermissionLevel.Minimal),
    AspNetHostingPermission(SecurityAction.InheritanceDemand,
        Level = AspNetHostingPermissionLevel.Minimal),
    DefaultEvent("Submit"),
    DefaultProperty("ButtonText"),
    ToolboxData("<{0}:CreateArticle runat="\""server\"> </{0}:CreateArticle>"),
    ]
    public class CreateArticleControl : Control, INamingContainer
    {
 
        private Label labelHeader;
        private Label labelIntro;
        private Label labelImage;
        private Label labelImageText;
        private Label labelText;
        private Label labelFileUploadStatus;
        private TextBox textBoxHeader;
        private TextBox textBoxIntro;
        private TextBox textBoxText;
        private TextBox textBoxImageText;
        private FileUpload fileUpload;
        private Button buttonCreateArticle;
 
        private static readonly object EventCreateArticleKey = new object();
 
        //public event EventHandler<CreateArticleEventArgs> CreateArticleClicked;

        #region Create Article Event Delegate
        [
        Category("Action"),
        Description("Raised when the user clicks the button.")
        ]
        public event EventHandler CreateArticle
        {
            add
            {
                Events.AddHandler(EventCreateArticleKey, value);
            }
            remove
            {
                Events.RemoveHandler(EventCreateArticleKey, value);
            }
        }
        #endregion
 
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }
 
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            HttpContext.Current.Trace.Warn("OnLoad");
            if (!Page.IsPostBack)
            {
                EnsureChildControls();
            }
        }
 
        protected override void CreateChildControls()
        {
            HttpContext.Current.Trace.Warn("CreateChildControls");
 
            // hlavicka
            labelHeader = new Label();
            labelHeader.Text = "Header:";
            Controls.Add(labelHeader);
 
            textBoxHeader = new TextBox();
            Controls.Add(textBoxHeader);
 
            // intro k clanku
            labelIntro = new Label();
            labelIntro.Text = "Intro:";
            Controls.Add(labelIntro);
 
            textBoxIntro = new TextBox();
            Controls.Add(textBoxIntro);
 
            // text clanku
            labelText = new Label();
            labelText.Text = "Text:";
            Controls.Add(labelText);
 
            textBoxText = new TextBox();
            Controls.Add(textBoxText);
 
            // upload obrazku
            labelImage = new Label();
            labelImage.Text = "Image Upload:";
            Controls.Add(labelImage);
 
            fileUpload = new FileUpload();
            Controls.Add(fileUpload);
 
            labelFileUploadStatus = new Label();
            labelFileUploadStatus.Text = "";
            Controls.Add(labelFileUploadStatus);
 
            labelImageText = new Label();
            labelImageText.Text = "Image Subscription:";
            Controls.Add(labelImageText);
 
            textBoxImageText = new TextBox();
            Controls.Add(textBoxImageText);
 
            // vloz clanok
            buttonCreateArticle = new Button();
            buttonCreateArticle.ID = "buttonInsertArticleID";
            buttonCreateArticle.Text = "Insert Article";
            buttonCreateArticle.Click += new EventHandler(buttonCreateArticle_Click);
 
            //base.CreateChildControls();
        }
 
        protected override void Render(HtmlTextWriter writer)
        {
            labelHeader.RenderControl(writer);
            textBoxHeader.RenderControl(writer);
            labelIntro.RenderControl(writer);
            textBoxIntro.RenderControl(writer);
            labelText.RenderControl(writer);
            textBoxText.RenderControl(writer);
            labelImage.RenderControl(writer);
            fileUpload.RenderControl(writer);
            labelFileUploadStatus.RenderControl(writer);
            labelImageText.RenderControl(writer);
            textBoxImageText.RenderControl(writer);
            buttonCreateArticle.RenderControl(writer);
        }
 
        protected virtual void OnCreateArticle(CreateArticleEventArgs e)
        {
            EventHandler SubmitHandler = (EventHandler)Events[EventCreateArticleKey];
            if (SubmitHandler != null)
            {
                SubmitHandler(this, e);
            }
        }
 
        void buttonCreateArticle_Click(object source, EventArgs e)
        {
            string filepath = "";
            if (fileUpload.HasFile)
            {
                filepath = HttpContext.Current.Server.MapPath("~/pictures/") + fileUpload.FileName;
                fileUpload.SaveAs(filepath);
            }
 
            OnCreateArticle(
                new CreateArticleEventArgs(true, new Article()
                {
                    Author = HttpContext.Current.User.Identity.Name,
                    CreationDate = DateTime.Now,
                    Header = textBoxHeader.Text,
                    Intro = textBoxIntro.Text,
                    Image = filepath,
                    ImageText = textBoxImageText.Text
                }));
        }
 
    }
}
 
// register it in web.config
<add tagPrefix="mycc" assembly="MyCompControl" namespace="MyCompControl" />
 
// create an instance
<mycc:CreateArticleControl ID="cac" runat="server"     oncreatearticle="cac_CreateArticle">        
</mycc:CreateArticleControl>
 
//event, which does nothing  :( 
protected void cac_CreateArticle(object sender, EventArgs e)
{
throw new NotImplementedException();
}
<>
 
A would be glad for any advice...
Questionhow to convert hex to rgb color code in asp.net PingroupDeenuji vellore6-Dec-12 23:14 
AnswerRe: how to convert hex to rgb color code in asp.net PinmvpRichard MacCutchan7-Dec-12 0:32 
Questionasp.net threads, see if thread with same name is running to wait a couple of seconds Pinmemberjkirkerx6-Dec-12 10:45 
AnswerRe: asp.net threads, see if thread with same name is running to wait a couple of seconds PinmentorKeith Barrow7-Dec-12 5:21 
GeneralRe: asp.net threads, see if thread with same name is running to wait a couple of seconds Pinmemberjkirkerx7-Dec-12 6:47 
QuestionPagination worries Pinmembercizu6-Dec-12 5:12 
AnswerRe: Pagination worries Pinmemberdeflinek7-Dec-12 1:40 
AnswerRe: Pagination worries PinmemberAnkitGoel.com10-Dec-12 17:33 
QuestionHtml Mail Formate Error Pinmembermukusingh5-Dec-12 18:49 
AnswerRe: Html Mail Formate Error Pinmemberjkirkerx6-Dec-12 10:41 
GeneralRe: Html Mail Formate Error Pinmembermukusingh6-Dec-12 19:18 
Questionhow to set og tag at runtime PinmemberJassim Rahma5-Dec-12 9:12 
AnswerRe: how to set og tag at runtime Pinmemberdeflinek7-Dec-12 1:50 
Questionis this a correct og prefix? PinmemberJassim Rahma5-Dec-12 7:36 
Questionasp.net vb PinmemberNada ALsalami5-Dec-12 3:09 
AnswerRe: asp.net vb Pinmemberryanb315-Dec-12 4:34 
GeneralRe: asp.net vb PinmemberNada ALsalami5-Dec-12 5:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 19 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid