突然间,动态创建的图像按钮的单击事件不会触发。

发布于 2024-07-21 08:10:03 字数 1882 浏览 3 评论 0原文

我有一个动态创建联系人表格的页面,如果联系人收到电子邮件,我还会创建一个带有单击事件的图像按钮。我在页面的其余部分有一个类似的功能,可以完美运行。 我之前使用过这个没有任何问题:

protected void CreateContactsList(IQueryable<AA_BranschFinder.Login.vyWebKontaktpersoner> lContacts) // Creates a table in the aspx from an IQueryable List 
        {
            if (1 == 1)
            {
                htmlTblContactsContent.Rows.Clear();

                foreach (var p in lContacts)
                {
                    HtmlTableRow tr = new HtmlTableRow();
                    HtmlTableCell tdName = new HtmlTableCell();
                    HtmlTableCell tdCompanyName = new HtmlTableCell();
                    HtmlTableCell tdEmailAdress = new HtmlTableCell();
                    tdName.InnerHtml = p.strFnamn + " " + p.strEnamn;
                    tdCompanyName.InnerHtml = p.strNamn;

                    //Displays an image if the contacts has an email
                    if (p.strEpost != null)
                    {
                        ImageButton imgEmail = new ImageButton();
                        imgEmail.CommandArgument = p.intKundID.ToString();
                        imgEmail.ImageUrl = "images/symbol_letter.gif";
                        imgEmail.CssClass = "letter";
                        imgEmail.Click +=new ImageClickEventHandler(imgEmail_Click);
                        tdEmailAdress.Controls.Add(imgEmail);
                    }
                    tr.Cells.Add(tdCompanyName);
                    tr.Cells.Add(tdEmailAdress);
                    tr.Cells.Add(tdName);
                    htmlTblContactsContent.Rows.Add(tr);
                }
            }

        }

        void imgEmail_Click(object sender, ImageClickEventArgs e)
        {

这里断点 抛出新的NotImplementedException(); 该

页面位于 java 弹出窗口内。 但我有类似事件创建的寻呼号码,效果很好。 但它们是链接按钮。

I have a page that dynamic create a table of contacts, if the contact got an email I also create an image button with a click event.I have a similar function in the rest of the page that works perfectly. And I used this before without any problems:

protected void CreateContactsList(IQueryable<AA_BranschFinder.Login.vyWebKontaktpersoner> lContacts) // Creates a table in the aspx from an IQueryable List 
        {
            if (1 == 1)
            {
                htmlTblContactsContent.Rows.Clear();

                foreach (var p in lContacts)
                {
                    HtmlTableRow tr = new HtmlTableRow();
                    HtmlTableCell tdName = new HtmlTableCell();
                    HtmlTableCell tdCompanyName = new HtmlTableCell();
                    HtmlTableCell tdEmailAdress = new HtmlTableCell();
                    tdName.InnerHtml = p.strFnamn + " " + p.strEnamn;
                    tdCompanyName.InnerHtml = p.strNamn;

                    //Displays an image if the contacts has an email
                    if (p.strEpost != null)
                    {
                        ImageButton imgEmail = new ImageButton();
                        imgEmail.CommandArgument = p.intKundID.ToString();
                        imgEmail.ImageUrl = "images/symbol_letter.gif";
                        imgEmail.CssClass = "letter";
                        imgEmail.Click +=new ImageClickEventHandler(imgEmail_Click);
                        tdEmailAdress.Controls.Add(imgEmail);
                    }
                    tr.Cells.Add(tdCompanyName);
                    tr.Cells.Add(tdEmailAdress);
                    tr.Cells.Add(tdName);
                    htmlTblContactsContent.Rows.Add(tr);
                }
            }

        }

        void imgEmail_Click(object sender, ImageClickEventArgs e)
        {

Breakpoint here
throw new NotImplementedException();
}

The page is living inside a java popup window. But I have paging numbers with similar event creation that works fine. But they are Linkbuttons.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天邊彩虹 2024-07-28 08:10:03

你在哪里调用你的 Create 方法? 您需要在其他事件处理程序运行之前执行此操作,最好是在 Page.Init 中。 否则,发回页面的数据将指示为尚不存在的控件触发的事件。

我还会确保您为 ImageButton 提供一个 ID。 这将使调试变得更加容易。

imgEmail.ID = String.Format("EmailImageButton_{0}", p.intKundID);

另一种解决方案是查看 Request 对象中的 __eventtarget 和 __eventargument 参数,并查看其中单击了哪个按钮。

Where are you calling your Create method? You need to do it before the other event handlers run, ideally in the Page.Init. Otherwise, the data posted back to the page are indicated an event firing for a control that doesn't yet exist.

I would also make sure that you give your ImageButton an ID. It will make debugging a lot easier.

imgEmail.ID = String.Format("EmailImageButton_{0}", p.intKundID);

An alternative solution is to look at the __eventtarget and __eventargument parameters in the Request object and see which button was clicked there.

逆光下的微笑 2024-07-28 08:10:03

您必须在每次回发时创建动态控件。 另请检查 imgEmail_Click 事件处理程序中的代码; 如果您使用 .NET IDE 的 Alt + Shift + F10 方法创建了事件处理程序方法,那么您可能没有删除此行 -

throw new Exception("The method or operation is not implemented.");

You'll have to create the dynamic controls on EVERY postback. Also check the code in the imgEmail_Click event handler; if you have created the event handler method using .NET IDE's Alt + Shift + F10 method, then there's a chance that you have not removed this line -

throw new Exception("The method or operation is not implemented.");
撩心不撩汉 2024-07-28 08:10:03

如果我没有记错的话,imagebutton 是一种提交类型的按钮,而 linkbutton 是带有 javascript 的 a 标签。 也许更改您的图像按钮点击(即 usesubmitbehaviour 设置为 false)将解决您的问题。

If I´m not misstaking the imagebutton is a submit kind of button while the linkbutton is an a-tag with javascript. Maybe changing your imagebutton click (ie usesubmitbehaviour set to false) will solve your problem.

小傻瓜 2024-07-28 08:10:03

确保事件处理程序已添加到您的回发中。 当仅在初始页面加载时添加它时,该事件将不会被处理! (我自己刚刚遇到并解决了这个问题。)

Make sure the event handler is added on your postbacks. When adding it just on initial page load, the event won't be handled! (Just encountered and solved this problem myself.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文