Not able to wire events in user control

用户在从Visual Studio 2003迁移到2005过程中遇到用户控件中链接按钮点击事件无法响应的问题,尝试多种解决办法仍未解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Re:Not able to wire events in user control

On Apr 5, 2:37 am, "Ben Rush" <kwen...@yahoo.com>wrote:
Quote
Can you be more specific and give us some sample code? I can guarantee that it's just as easy (and in some cases easier) in VS2005. What you're doing works....so something else is broken. -- ~~~~~~~~~~~ Ben Rush http://www.ben-rush.net/blog <jfoll...@tcimex.com>wrote in message news:1175743054.435511.254960@q75g2000hsh.googlegroups.com...
Quote
I am trying to add a basic user control to a web site; coming from visual studio 2003 this was extremely easy. I would just add the user control and then add the controls that I want on that user control, but I am not able to get a basic link button to click. This seems so ridiculously basic, but I am not able to get this to work. What am I missing?- Hide quoted text -
- Show quoted text -
Here is the code: using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using CustomDesignCabinetry.Components; public partial class controls_KitchenCabinetOrderForm : System.Web.UI.UserControl { string lnkHref = "javascript:OpenBrWindow('%KitchenPage %','winFaq','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no','KitchenPageHeight','KitchenPageWidth','true');"; public int KitchenID { get { return int.Parse(this.lblKitchenID.Text); } set { lblKitchenID.Text = value.ToString(); LoadKitchen(); } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) SetItemsVisibility(); } void lnkShow_Click(object sender, EventArgs e) { this.SetItemsVisibility(); } private void SetItemsVisibility() { this.lnItems.Visible = !this.lnItems.Visible; //if (this.lnItems.Visible) // lnkShow.Text = "(hide)"; //else // lnkShow.Text = "(show)"; } private void LoadKitchen() { CustomDesignCabinetry.Components.Kitchen kit = new Kitchen(GlobalInfo.ConnString); kit.RetrieveKitchenInfo(this.KitchenID); string tmp = this.lnkHref; tmp = tmp.Replace("%KitchenPage%", kit.KitchenPage); tmp = tmp.Replace("KitchenPageHeight", kit.KitchenPageHeight.ToString()); tmp = tmp.Replace("KitchenPageWidth", kit.KitchenPageWidth.ToString()); this.lnkKitchen.HRef = tmp; this.imgKitchenDoor.Src = "../images/" + kit.DisplayImage; DataSet ds = kit.RetrieveKitchenCabinetsForOrderForm(this.KitchenID, GlobalInfo.CurrentOrderID); this.grdKitchenBrand.DataSource = ds; this.grdKitchenBrand.DataBind(); bool FoundSaleItem = false; foreach (DataRow dr in ds.Tables[0].Rows) { if(!dr.IsNull("Sale_Price")) if (decimal.Parse(dr["Sale_Price"].ToString())>0) { FoundSaleItem = true; break; } } grdKitchenBrand.Columns[5].Visible = FoundSaleItem; this.lnkBrand.Text = new Brand(kit.ConnString).GetBrandName(kit.BrandID); } protected void lnkBrand_Click(object sender, EventArgs e) { this.SetItemsVisibility(); } } Here is the HTML: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="KitchenCabinetOrderForm.ascx.cs" Inherits="controls_KitchenCabinetOrderForm" %> <table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td colspan="2" align="left"><asp:Label ID="lblKitchenID" runat="server" Text="0" Visible="False"></asp:Label> <asp:LinkButton ID="lnkBrand" runat="server" Font-Bold="True" Font- Names="Verdana" ForeColor="#FFE3A9" OnClick="lnkBrand_Click">Brand</ asp:LinkButton>&nbsp; <asp:LinkButton ID="lnkShow" runat="server" Font-Names="Verdana" Font- Size="X-Small" ForeColor="#FFE3A9">(show)</asp:LinkButton> </td></tr> <tr id="lnItems" runat="server" valign="top"><td width="20%"> <a href="javascript:OpenBrWindow('k5.htm','winFaq','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no','798','585','true');" runat="server" id="lnkKitchen"> <img border="0" src="../images/k5.jpg" width="129" height="197" align="right" id="imgKitchenDoor" runat="server"/></a> </td><td width="80%"> <asp:GridView ID="grdKitchenBrand" runat="server" AutoGenerateColumns="False" ForeColor="#FFE3A9" Width="100%"> <Columns> <asp:BoundField DataField="Kitchen_Cabinet_ID" HeaderText="Kitchen_Cabinet_ID" Visible="False" /> <asp:BoundField DataField="Cabinet_Type_Name" HeaderText="Type" /> <asp:HyperLinkField DataNavigateUrlFormatString="ItemNumHelp.aspx?Item_Num={0}" DataTextField="Item_Num" HeaderText="Item Num"> <ControlStyle Font-Names="Verdana" Font- Size="Smaller" ForeColor="#FFE3A9" /> </asp:HyperLinkField> <asp:BoundField DataField="Retail" DataFormatString="{0:C}" HeaderText="Retail" /> <asp:BoundField DataField="Our_Price" DataFormatString="{0:C}" HeaderText="Our Price" /> <asp:BoundField DataField="Sale_Price" DataFormatString="{0:C}" HeaderText="Sale Price" /> <asp:TemplateField HeaderText="Qty"> <ItemTemplate> <asp:TextBox ID="txtQty" runat="server" MaxLength="4" Width="32px">0</asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> <RowStyle BackColor="#44260E" /> <HeaderStyle BackColor="#755A3D" /> <AlternatingRowStyle BackColor="#5C4000" /> </asp:GridView> </td></tr> </table> I have tried adding like I would have found in VS2003: override protected void OnInit(EventArgs e) { InitializeComponent(); base.OnInit(e); } private void InitializeComponent() { this.lnkBrand.Click += new EventHandler(this.lnkBrand_Click); this.lnkShow.Click += new EventHandler(lnkShow_Click); //this.Page.Load += new System.EventHandler(this.Page_Load); } I cannot get either lnkBrand or lnkShow to respond to click events. This has got to be super smple, but I have been trying to figure it out for a while. TIA,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值