Results 1 to 13 of 13

Thread: LoadControl() Postback and events

  1. #1

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    LoadControl() Postback and events

    I am having a problemn where I am loading an UserControl. The user control has two buttons Move Up and Move Down.

    The events are wired, and there is code in the buttons; but nothing happens. Even when I click the button. Nothing happens. Post back occurs but the event does not fire and my picture doesn't move up one in it's sequence.

    I had the problem before and I messed with it for days and it started to work. I don't know or remember why. HELP!!!!



    Thanks.
    Magiaus

    If I helped give me some points.

  2. #2

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    I'm seeing the problem again. The controls have to be loaded in the same order to load the viewstate and have postback work.

    I just made a simple one page web that loads a control with a button. It works. When I click the button a label says clicked.

    It works with ViewState disabled for the panel I'm loading too, but of cource only one control keeps the record of being clicked.

    urg
    Magiaus

    If I helped give me some points.

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    So you solved it...?

  4. #4

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    not yet.
    Magiaus

    If I helped give me some points.

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Post your code please...

  6. #6

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    i will tomorrow
    Magiaus

    If I helped give me some points.

  7. #7

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    the Load Routine

    PHP Code:
                Business.Images.SourceCollection imgs = new Business.Images.SourceCollection(ProductExKey);
                
    System.Web.UI.Control img;
                
                
    pnl_newSourcePictures.Controls.Clear();
                for(
    int i 0pnl_newSourcePictures.Controls.Counti++)
                {
                    
    pnl_newSourcePictures.Controls.RemoveAt(i);
                }
                
                if(
    imgs.Count 0)
                {
                    for(
    int i 0imgs.Count;i++)
                    {
                        
    img LoadControl("../../UserControls/Forms/Edit/Images/SourceSequence.ascx");
                
                        ((
    Web.UserControls.Forms.Edit.Images.SourceSequence)img).SourceKey imgs[i].Key;
                        ((
    Web.UserControls.Forms.Edit.Images.SourceSequence)img).ImageKey imgs[i].ImageKey;
                                    
                        
    pnl_newSourcePictures.Controls.Add(img);
                    }
                } 
    Magiaus

    If I helped give me some points.

  8. #8

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    The Control loads fine and it in turn loads the image fine. But the events for the buttons won't fire. At first I was loading inside another user control but last night I put it on a page just to see... it didn't work there either.
    Last edited by Magiaus; Aug 25th, 2004 at 07:58 AM.
    Magiaus

    If I helped give me some points.

  9. #9

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    the control

    PHP Code:
        using System;
        
    using System.Data;
        
    using System.Drawing;
        
    using System.Web;
        
    using System.Web.UI.WebControls;
        
    using System.Web.UI.HtmlControls;

        
    /// <summary>
        ///        Summary description for SourceSequence.
        /// </summary>
        
    public abstract class SourceSequence System.Web.UI.UserControl
        
    {
            protected 
    System.Web.UI.WebControls.Button btn_down;
            protected 
    System.Web.UI.WebControls.Button btn_up;
            protected 
    System.Web.UI.WebControls.Button btn_delete;
            protected 
    System.Web.UI.WebControls.Image imgSrc;


            private 
    void Page_Load(object senderSystem.EventArgs e)
            {
                if(!
    IsPostBack)
                {
                    try
                    {
                        
    SourceKey SourceKey;
                    }
                    catch(
    System.Exception ex)
                    {
                        
    ex ex;
                        
    SourceKey System.Guid.Empty;
                    }

                    try
                    {
                        
    ImageKey ImageKey;
                    }
                    catch(
    System.Exception ex)
                    {
                        
    ex ex;
                        
    ImageKey System.Guid.Empty;
                    }
                }
            }
            public 
    System.Guid SourceKey
            
    {
                
    get{return (System.Guid)ViewState["-SourceKey"];}
                
    set{ViewState["-SourceKey"] = value;}
            }

            public 
    System.Guid ImageKey
            
    {
                
    get{return (System.Guid)ViewState["pid"];}
                
    set
                
    {
                    
    ViewState["pid"] = value;

                    if(
    ImageKey != System.Guid.Empty)
                    {
                        
    imgSrc.ImageUrl Helpers.Common.AppSetting("-baseURL") + "Images/Image.aspx?pid=" value.ToString();
                    }
                }
            }
            
    #region Web Form Designer generated code
            
    override protected void OnInit(EventArgs e)
            {
                
    //
                // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                //
                
    InitializeComponent();
                
    base.OnInit(e);
            }
            
            
    ///        Required method for Designer support - do not modify
            ///        the contents of this method with the code editor.
            /// </summary>
            
    private void InitializeComponent()
            {
                
    this.btn_up.Click += new System.EventHandler(this.btn_up_Click);
                
    this.btn_down.Click += new System.EventHandler(this.btn_down_Click);
                
    this.btn_delete.Click += new System.EventHandler(this.btn_delete_Click);
                
    this.Load += new System.EventHandler(this.Page_Load);

            }
            
    #endregion

            
    private void btn_up_Click(object senderSystem.EventArgs e)
            {
                if(
    SourceKey != System.Guid.Empty)
                {
                    
    Business.Images.Source src = new Business.Images.Source(SourceKey);
                    
                    if(
    src.Sequence != Business.Images.Source.Count() - 1)
                    {
                        
    Business.Images.Source.ReSequence(srcsrc.Sequence 1);
                    }
                    
    src null;
                }
            }

            private 
    void btn_down_Click(object senderSystem.EventArgs e)
            {
                if(
    SourceKey != System.Guid.Empty)
                {
                    
    Business.Images.Source src = new Business.Images.Source(SourceKey);
                    if(
    src.Sequence != 0)
                    {
                        
    Business.Images.Source.ReSequence(srcsrc.Sequence 1);
                    }
                    
    src null;
                }
            }

            private 
    void btn_delete_Click(object senderSystem.EventArgs e)
            {
                
    Business.Images.Source.Delete(new Business.Images.Source(SourceKey));
            }
        } 
    Magiaus

    If I helped give me some points.

  10. #10

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    I don't know. I know I had fixed this before somehow but I had thought SmartNavigation = true was causing it..... SmartNav is off......
    Magiaus

    If I helped give me some points.

  11. #11
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well since it worked before....

    Problems I have experienced with events not wiring usually indicate the control is not matching up with the post data. So the framework ignores the events either because the control is reloading itself anew, instead of restructuring itself from the posted viewstate.

    Your code seems pretty spot on,so my guess is during initialization, you are not assigning an ID for the control, so the framework gives it a new ID, thus the events don't wire.

    Try explicitly declaring an ID for your control first during the Load, and see if that fixes it. Or it could be the ID's of the buttons...
    Last edited by nemaroller; Aug 25th, 2004 at 08:44 AM.

  12. #12

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Cool duh

    It helps to declare your Control outside the method that loads it......
    Magiaus

    If I helped give me some points.

  13. #13

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    I had another glitch where it wasn't working after the first postback so I did what you suggested and set an id. It fixed everything.

    thanks
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width