Click here to Skip to main content
15,889,034 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionlinq connection in asp.net Pin
JonBrynjar8-Dec-12 3:58
JonBrynjar8-Dec-12 3:58 
AnswerRe: linq connection in asp.net Pin
AmitGajjar11-Dec-12 7:00
professionalAmitGajjar11-Dec-12 7:00 
QuestionChange root path Pin
#realJSOP8-Dec-12 3:40
mve#realJSOP8-Dec-12 3:40 
AnswerRe: Change root path Pin
Richard Deeming10-Dec-12 1:35
mveRichard Deeming10-Dec-12 1:35 
GeneralRe: Change root path Pin
#realJSOP10-Dec-12 1:42
mve#realJSOP10-Dec-12 1:42 
AnswerRe: Change root path Pin
AmitGajjar11-Dec-12 7:10
professionalAmitGajjar11-Dec-12 7:10 
QuestionUpdating the column using entity framework Pin
indian1437-Dec-12 12:46
indian1437-Dec-12 12:46 
Questionasp.NET composite control cannot raise an event Pin
michal.cerbak7-Dec-12 4:50
michal.cerbak7-Dec-12 4:50 
C#
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 Pin
Deenuji6-Dec-12 23:14
Deenuji6-Dec-12 23:14 
AnswerRe: how to convert hex to rgb color code in asp.net Pin
Richard MacCutchan7-Dec-12 0:32
mveRichard MacCutchan7-Dec-12 0:32 
Questionasp.net threads, see if thread with same name is running to wait a couple of seconds Pin
jkirkerx6-Dec-12 10:45
professionaljkirkerx6-Dec-12 10:45 
AnswerRe: asp.net threads, see if thread with same name is running to wait a couple of seconds Pin
Keith Barrow7-Dec-12 5:21
professionalKeith Barrow7-Dec-12 5:21 
GeneralRe: asp.net threads, see if thread with same name is running to wait a couple of seconds Pin
jkirkerx7-Dec-12 6:47
professionaljkirkerx7-Dec-12 6:47 
QuestionPagination worries Pin
cizu6-Dec-12 5:12
professionalcizu6-Dec-12 5:12 
AnswerRe: Pagination worries Pin
Deflinek7-Dec-12 1:40
Deflinek7-Dec-12 1:40 
AnswerRe: Pagination worries Pin
AnkitGoel.com10-Dec-12 17:33
AnkitGoel.com10-Dec-12 17:33 
QuestionHtml Mail Formate Error Pin
mukusingh5-Dec-12 18:49
mukusingh5-Dec-12 18:49 
AnswerRe: Html Mail Formate Error Pin
jkirkerx6-Dec-12 10:41
professionaljkirkerx6-Dec-12 10:41 
GeneralRe: Html Mail Formate Error Pin
mukusingh6-Dec-12 19:18
mukusingh6-Dec-12 19:18 
Questionhow to set og tag at runtime Pin
Jassim Rahma5-Dec-12 9:12
Jassim Rahma5-Dec-12 9:12 
AnswerRe: how to set og tag at runtime Pin
Deflinek7-Dec-12 1:50
Deflinek7-Dec-12 1:50 
Questionis this a correct og prefix? Pin
Jassim Rahma5-Dec-12 7:36
Jassim Rahma5-Dec-12 7:36 
Questionasp.net vb Pin
NadaSaif5-Dec-12 3:09
NadaSaif5-Dec-12 3:09 
AnswerRe: asp.net vb Pin
ZurdoDev5-Dec-12 4:34
professionalZurdoDev5-Dec-12 4:34 
GeneralRe: asp.net vb Pin
NadaSaif5-Dec-12 5:05
NadaSaif5-Dec-12 5:05 

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

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