Not able to wire events in user control
2008-06-30 17:04
351 查看
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>
<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,
122851: Themes and web.config
122852: new features on 2003
122853: IIS6 and downloadable JAR file
122854: Center Alignment
122855: Warning: Page has Expired
122856: Turning on security
122857: Problem with database (Login failed for user 'X')
122858: Simple question.
122859: popup window "This resource cannot be found"
122860: Error: Must Declare Variable
122861: Identifying what is behind W3WP.exe
122862: how to check given value is numeric or not
122863: PBM: Authentication popup when uploading from a web dialog
122864: hyperlink column in datagrid in web user control
122865: http://www.databaseforum.info/8/9/1b2d2f6c762322cc.html" target=_blank>Debug = true/false in web.config
122866: Can't upload subwebs
122867: Sort list via client code only
122868: Profiling aspnet_wp.exe?
122869: ASP and MySQL
122870: Disallow download of certain file type
122871: Gridview bound to Datatable. Update doesn't work, need help
122872: ASP connect to dot net SOAP webserivce
122873: default value in field
122874: Subdomain in Frontpage
122875: window.close in vb.net??
122876: Samrt Client ?'s
122877: CreateObject("Scripting.FileSystemObject")
122878: ApplicationPool Identity DCOM Local Activation
122879: IIS and cross-domain network resource access permissions
122880: IIS 6.0 Debugging ASP 3.0
122881: Using PhP.
122882: Validation for user controls
相关文章推荐
- Not able to wire events in user control
- The MSSQL Reporting Services (SSRS) service failed to start : The service did not respond to the start or control request in a timely fashion
- how to resovle The type 'UserControl' does not support direct content
- How to run a user control assembly that is hosted on Internet Information Services (IIS) in Internet Explorer
- How to call page method in UserControl?
- Raise event from user control to main page / Event delegation from user control to aspx page in ASP.
- IIS无法启动,报错:The service did not respond to the start or control request in a timely fashion.
- How to fix "'user' is not in sudoers" in CentOS
- The user running validate, does not have permissions to create computer objects in the 'x.com
- Comparison of user class objects is not supported in Linq to entities
- In RadGrid, How to get the control inside usercontrol
- How to start a second thread in an MFC-based ActiveX control to fire events in Visual C++
- A read-only user or a user in a read-only database is not permitted to disable
- 【Visual Studio】The project appears to be under source control, but the associated source control plug-in is not installed on this computer
- Ceph安装QEMU报错:User requested feature rados block device configure was not able to find it
- One reason for not able to show chinese correctly in installation
- TIP: when you get a message in job log user [Dr. Who] is not authorized to view the log
- How to create a read-only user in TFS source control
- IIS Default Web Site : The service did not response to the start or control request in a timely fashion
- #364 – 日历控件日期多选(Allowing a User to Select Multiple Dates in a Calendar Control)