|
-
Aug 23rd, 2004, 11:35 PM
#1
Thread Starter
Frenzied Member
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.
-
Aug 23rd, 2004, 11:52 PM
#2
Thread Starter
Frenzied Member
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.
-
Aug 24th, 2004, 09:06 AM
#3
I wonder how many charact
-
Aug 24th, 2004, 09:38 AM
#4
Thread Starter
Frenzied Member
Magiaus
If I helped give me some points.
-
Aug 24th, 2004, 09:41 AM
#5
I wonder how many charact
-
Aug 24th, 2004, 05:01 PM
#6
Thread Starter
Frenzied Member
Magiaus
If I helped give me some points.
-
Aug 25th, 2004, 07:50 AM
#7
Thread Starter
Frenzied Member
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 = 0; i < pnl_newSourcePictures.Controls.Count; i++)
{
pnl_newSourcePictures.Controls.RemoveAt(i);
}
if(imgs.Count > 0)
{
for(int i = 0; i < imgs.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.
-
Aug 25th, 2004, 07:52 AM
#8
Thread Starter
Frenzied Member
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.
-
Aug 25th, 2004, 07:53 AM
#9
Thread Starter
Frenzied Member
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 sender, System.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 sender, System.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(src, src.Sequence + 1);
}
src = null;
}
}
private void btn_down_Click(object sender, System.EventArgs e)
{
if(SourceKey != System.Guid.Empty)
{
Business.Images.Source src = new Business.Images.Source(SourceKey);
if(src.Sequence != 0)
{
Business.Images.Source.ReSequence(src, src.Sequence - 1);
}
src = null;
}
}
private void btn_delete_Click(object sender, System.EventArgs e)
{
Business.Images.Source.Delete(new Business.Images.Source(SourceKey));
}
}
Magiaus
If I helped give me some points.
-
Aug 25th, 2004, 07:57 AM
#10
Thread Starter
Frenzied Member
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.
-
Aug 25th, 2004, 08:31 AM
#11
I wonder how many charact
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.
-
Aug 25th, 2004, 10:19 AM
#12
Thread Starter
Frenzied Member
duh
It helps to declare your Control outside the method that loads it......
Magiaus
If I helped give me some points.
-
Aug 27th, 2004, 02:48 PM
#13
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|