NET不火的OnClick事件处理程序

NET不火的OnClick事件处理程序

本文介绍了在的ImageButton直放站ASP.NET不火的OnClick事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个Repeater控件内的的ImageButton。我重视的事件处理程序到的ImageButton的onclick事件。但是,当我点击的ImageButton事件不会被解雇。请让我知道如果我失去了一些东西。谢谢

我已经附加aspx页面和codebehind文件

 <%@页面语言=C#AutoEventWireup =真codeBehind =AddTag.aspx.cs继承=IV.Web.Searchv2UI.AddTag。 AddTagEnableEventValidation =假的EnableViewState =真正的%GT;!< D​​OCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
<头=服务器>
    <标题>    < /标题>
    <风格类型=文/ CSS>
    。新增标签颜色要求的
{
    颜色:红色;
}。新增标签浮动右
{
    浮动:权利;
}    < /风格>
    <脚本类型=文/ JavaScript的>
        功能GetRadWindow(){
            VAR oWindow = NULL;
            如果(window.radWindow)
                oWindow = window.RadWindow; //将在万盎司的工作在所有情况下,包括经典对话
            否则,如果(window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow; // IE(以及万盎司以及)
            返回oWindow;
        }        功能取消(){
            //干净保存搜索领域
            document.forms [0] .reset段();            //获取到当前RadWindow一个参考
            变种oWindow = GetRadWindow();
            oWindow.close();
        }    < / SCRIPT>
< /头>
<身体GT;
    <表ID =formAddTag=服务器>        <% - RadScriptManager - %GT;
        < Telerik的:RadScriptManager ID =radScriptManager=服务器/>
        <% - RadScriptManager - %GT;         <% - Telerik的装饰 - %GT;
        < Telerik的:RadFormDecorator ID =radFormDecorator=服务器DecoratedControls =全部/>
        <% - Telerik的装饰 - %GT;        <% - StyleSheetManager - %GT;
        <跑道:StyleSheetManager ID =runwayStyleSheetManager=服务器/>
        <% - StyleSheetManager - %GT;
        < Telerik的:RadAjaxLoadingPanel ID =radAjaxLoadingPanel=服务器/>        < Telerik的:RadAjaxPanel ID =radAjaxPanelAddTag=服务器的CssClass =跨度-12LoadingPanelID =radAjaxLoadingPanel>
            < D​​IV CLASS =跨度-12最后高度2>
                < D​​IV CLASS =跨度7的高度-2>                        < ASP:标签ID =labelAddTag文本=标签=服务器的CssClass =颜色-A-4/>
                        < BR />
                        <跨度>&安培; NBSP;输入用逗号分隔的标签< / SPAN>
                    < / DIV>
                < / DIV>
                < BR />
                < D​​IV CLASS =跨度7上次高度2>
                    < Telerik的:RadTextBox ID =radTextBoxTags=服务器MAXLENGTH =45WIDTH =98%/>
                    < ASP:的RequiredFieldValidator ID =requiredFieldValidatorSearchName=服务器的ControlToValidate =radTextBoxTags
                                                显示=无的ErrorMessage =标签是必需的。>
                    < / ASP:&的RequiredFieldValidator GT;
                < / DIV>
                < D​​IV CLASS =跨度5最后高度2>                        < ASP:按钮的ID =buttonAdd=服务器文本=添加的CausesValidation =真WIDTH =×45像素的OnClick =buttonAdd_Click/>
                        < ASP:按钮的ID =buttonCancel=服务器文本=取消的CausesValidation =假WIDTH =50像素的OnClientClick =取消();返回false; />
                 < / DIV>
                   < BR />
                    < D​​IV CLASS =跨度-12>
                   < ASP:直放站ID =repeaterTag=服务器>                    <&ItemTemplate中GT;                        < ASP:标签ID =labelTag=服务器文本=<%#的Container.DataItem%GT;>< / ASP:标签>
                        < ASP:ImageButton的=服务器ID =imageButtonRemove的ImageUrl =〜/ App_Themes文件/ ChromeTheme /图片/ message_close_9x9.png工具提示=删除的OnClick =imageButtonRemove_Click/>                        <跨度>&安培; NBSP;< / SPAN>                     < / ItemTemplate中>
                   < / ASP:直放站>
               < / DIV>        < / Telerik的:RadAjaxPanel>
        < /表及GT;
< /身体GT;
< / HTML>

隐藏文件的code是如下:

 使用系统;
使用System.Collections.Generic;
System.Collections中使用;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;命名空间IV.Web.Searchv2UI.AddTag
{
公共部分类AddTag:System.Web.UI.Page
{
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
如果(!Page.IsPostBack)
{
清单<串GT;标签=新的List<串GT;();tags.Add(半导体);
tags.Add(电子);
tags.Add(我们);的ViewState [标签] =标签;repeaterTag.DataSource =标签;
repeaterTag.DataBind();}
}保护无效buttonAdd_Click(对象发件人,EventArgs的发送)
{
清单<串GT;标签=(列表<串GT;)的ViewState [标签];
串[] newTags = radTextBoxTags.Text.Split(,);
如果(newTags.Length大于0)
{的foreach(在newTags字符串标记)
{
如果(!tags.Contains(标签))
{
tags.Add(标签);
}
}
}
的ViewState [标签] =标签;
repeaterTag.DataSource =标签;
repeaterTag.DataBind();radTextBoxTags.Text =的String.Empty;
}保护无效imageButtonRemove_Click(对象发件人,EventArgs的发送)
{
清单<串GT;标签=(列表<串GT;)的ViewState [标签];
的ImageButton按钮=(ImageButton的)寄件人;面板面板=(面板)button.Parent;
字符串标记=((标签)(panel.Controls [1]))文本。tags.Remove(标签);
的ViewState [标签] =标签;
repeaterTag.DataSource =标签;
repeaterTag.DataBind();
}
}
}


解决方案

我有DET同样的问题,并通过AV ASP解决它:LinkBut​​ton的使用与按需事件。我的标记和code背后如下公布。

标记:

 < ASP:直放站ID =rptRecipients=服务器>
            <&HeaderTemplate中GT;
                <表>
            < / HeaderTemplate中>
            <&ItemTemplate中GT;
                &所述; TR>
                    &所述; TD>
                        < ASP:标签ID =LabelRecipient文本='<%#的eval(值)%GT;' =服务器>< / ASP:标签>
                    < / TD>
                    &所述; TD>
                    < ASP:LinkBut​​ton的按需=lbRemove_CommandCommandArgument ='<%#的eval(密钥)%GT;'
                            的CommandName =删除=服务器>
                        < ASP:图像的ImageUrl =〜/图片/ delete.png=服务器/>
                    < / ASP:LinkBut​​ton的>
                    < / TD>
                < / TR>
            < / ItemTemplate中>
            < FooterTemplate>
                < /表>
            < / FooterTemplate>
        < / ASP:直放站>

背后code:

 保护无效lbRemove_Command(对象发件人,CommandEventArgs E)
    {
        开关(e.CommandName)
        {
            案删除:
                Recipients.Remove(e.CommandArgument.ToString());
                rptRecipients.DataSource =收件人;
                rptRecipients.DataBind();
                打破;        }
    }

I have an ImageButton inside a repeater control. I have attached an eventhandler to the OnClick event of the ImageButton. But when I click the ImageButton the event does not get fired. Please Let me know if I am missing something. Thanks

I've attached the aspx page and the codebehind file

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddTag.aspx.cs" Inherits="IV.Web.Searchv2UI.AddTag.AddTag" EnableEventValidation="false" EnableViewState="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>

    </title>
    <style type="text/css">
    .add-tag-color-required
{
    color:Red;
}

.add-tag-float-right
{
    float:right;
}

    </style>
    <script type="text/javascript">
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.RadWindow; //Will work in Moz in all cases, including classic dialog
            else if (window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow; //IE (and Moz as well)
            return oWindow;
        }

        function Cancel() {
            // clean save search fields
            document.forms[0].reset();

            //get a reference to the current RadWindow
            var oWindow = GetRadWindow();
            oWindow.close();
        }

    </script>
</head>
<body >
    <form id="formAddTag" runat="server">

        <%-- RadScriptManager --%>
        <telerik:RadScriptManager ID="radScriptManager" runat="server" />
        <%-- RadScriptManager --%>

         <%-- Telerik Decorator --%>
        <telerik:RadFormDecorator id="radFormDecorator" runat="server" DecoratedControls="All" />
        <%-- Telerik Decorator --%>

        <%-- StyleSheetManager --%>
        <runway:StyleSheetManager ID="runwayStyleSheetManager" runat="server" />
        <%-- StyleSheetManager --%>




        <telerik:RadAjaxLoadingPanel ID="radAjaxLoadingPanel" runat="server" />

        <telerik:RadAjaxPanel ID="radAjaxPanelAddTag" runat="server" CssClass="span-12" LoadingPanelID="radAjaxLoadingPanel">
            <div class="span-12 last height-2">
                <div class="span-7 height-2">

                        <asp:Label ID="labelAddTag" Text=" Tags" runat="server" CssClass="color-a-4" />
                        <br/>
                        <span>&nbsp;Enter tags seperated by commas.</span>
                    </div>
                </div>
                <br/>
                <div class="span-7 last height-2">
                    <telerik:RadTextBox ID="radTextBoxTags" runat="server" MaxLength="45" Width="98%" />
                    <asp:RequiredFieldValidator ID="requiredFieldValidatorSearchName" runat="server" ControlToValidate="radTextBoxTags"
                                                Display="None" ErrorMessage="Tag is required.">
                    </asp:RequiredFieldValidator>
                </div>


                <div class="span-5 last height-2">

                        <asp:Button id="buttonAdd" runat="server" Text="Add" CausesValidation="true" Width="45px" OnClick="buttonAdd_Click" />
                        <asp:Button id="buttonCancel" runat="server" Text="Cancel" CausesValidation="false" Width="50px" OnClientClick="Cancel(); return false;" />
                 </div>
                   <br />
                    <div class="span-12">
                   <asp:Repeater ID="repeaterTag" runat="server">

                    <ItemTemplate>

                        <asp:Label ID="labelTag" runat="server" Text="<%#Container.DataItem %>"></asp:Label>
                        <asp:ImageButton runat="server" ID="imageButtonRemove" ImageUrl="~/App_Themes/ChromeTheme/Images/message_close_9x9.png" ToolTip="Remove" OnClick="imageButtonRemove_Click" />

                        <span>&nbsp;</span>

                     </ItemTemplate>
                   </asp:Repeater>
               </div>

        </telerik:RadAjaxPanel>
        </form>
</body>
</html>

The code behind file is as follows.

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IV.Web.Searchv2UI.AddTag
{
	public partial class AddTag : System.Web.UI.Page
	{


		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				List<string> tags = new List<string>();

				tags.Add("semiconductor");
				tags.Add("electronics");
				tags.Add("us");

				ViewState["Tags"] = tags;

				repeaterTag.DataSource = tags;
				repeaterTag.DataBind();



			}
		}

		protected void buttonAdd_Click(object sender, EventArgs e)
		{
			List<string> tags = (List<string>)ViewState["Tags"];
			string[] newTags = radTextBoxTags.Text.Split(',');
			if (newTags.Length > 0)
			{

				foreach(string tag in newTags)
				{
					if (!tags.Contains(tag))
					{
						tags.Add(tag);
					}
				}
			}
			ViewState["Tags"] = tags;
			repeaterTag.DataSource = tags;
			repeaterTag.DataBind();

			radTextBoxTags.Text = string.Empty;
		}

		protected void imageButtonRemove_Click(object sender, EventArgs e)
		{
			List<string> tags = (List<string>)ViewState["Tags"];
			ImageButton button = (ImageButton)sender;

			Panel panel = (Panel)button.Parent;
			string tag = ((Label)(panel.Controls[1])).Text;

			tags.Remove(tag);
			ViewState["Tags"] = tags;
			repeaterTag.DataSource = tags;
			repeaterTag.DataBind();
		}
	}
}
解决方案

I had det same problem, and solved it by using av asp:Linkbutton with a with the "OnCommand" event. My markup and code behind is posted below.

Markup:

<asp:Repeater ID="rptRecipients" runat="server">
            <HeaderTemplate>
                <table>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Label ID="LabelRecipient" Text='<%# Eval("Value")%>' runat="server"></asp:Label>
                    </td>
                    <td>
                    <asp:LinkButton OnCommand="lbRemove_Command"  CommandArgument='<%# Eval("Key")%>'
                            CommandName="Remove"  runat="server">
                        <asp:Image ImageUrl="~/Images/delete.png" runat="server" />
                    </asp:LinkButton>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

Code behind:

 protected void lbRemove_Command(object sender, CommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "Remove":
                Recipients.Remove(e.CommandArgument.ToString());
                rptRecipients.DataSource = Recipients;
                rptRecipients.DataBind();
                break;

        }
    }

这篇关于在的ImageButton直放站ASP.NET不火的OnClick事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:59