English 中文(简体)
三. 业余与业余学生协会之间的活动
原标题:Events between an ASPX and ASCX

i m a beginner in .NET, and search since yesterday morning to resolve my problem without finding the solution.

我的问题是:

我以这种方式积极建立一些用户控制,因为我需要给出参数:

List<ANNOUNCEMENT> listAnnouncement = getAnnoucements();
foreach(ANNOUNCEMENT ann in listAnnouncement)
{
    if(ann.IS_CURRENT_ANNOUNCEMENT && currentAnnouncement == null)
    {
         currentAnnouncement = ann;
    }
    List<Object> listParams = new List<Object>();
    listParams.Add(ann);
    AnnouncementPresentation ap = (AnnouncementPresentation)(Controller.LoadControl(Page, "~/UserControls/AnnouncementPresentation.ascx", listParams.ToArray()));
    /* important for the end of the method */
    ap.modifyAnnouncementButtonClick += new EventHandler(modifyAnnouncementButtonClick);
    pnl_announcements.Controls.Add(ap);
}

In this ASCX, I have a button, and when user will click on it, I want to call a method contained in my ASPX, so I do this in the ASCX :

public event EventHandler modifyAnnouncementButtonClick;
protected void btn_modify_announcement_Click(object sender, EventArgs e)
{
    PageAdminAnnonces.currentAnnouncement = annonce;
    modifyAnnouncementButtonClick(sender, e);
}

And this in the ASPX :

protected void modifyAnnouncementButtonClick(object sender, EventArgs e)
{
     initListOfAnnouncement();
     lbl_errors.Text = currentAnnouncement.TITLE;
}

我认为一切都可行,但问题是: 它一劳永逸,在方法结束时,我删除我可以看到的我的ASCX,并创建新的ASCX。 但是,他们没有办法,当我再次点击时,没有做任何事,因此,协会X被重载。 在重载后,它再次运作。

Do i do something wrong?

最佳回答

根据评论中的信息,我相信,你的解决办法不会奏效,因为你正在重新调整中的活动处理方法的控制,该方法很晚,而且不应用于增加控制。

As mentioned in the comments, I suggest you to create the controls in Page_Init or Page_Load and not recreate them in the button s Click handling method. You should also assign a unique ID to each of them. Then, in the Click handler, you can use FindControl method to acces the created controls. Alternatively you can just save the references to the controls upon creation, so you can access them later easily.

有用联系:

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签