Hi,
I trying to build a table using the TableControl in order manage som image files. What I would like to do is to load an image combined with a linkbutton into each cell and to delete the image if you click it.
The table is created complete with links and images, but the eventhandler attached to the linkbutton is not reached when I activate the linkbutton.
I assume that it has something to do with how the page is loaded, but I cannot figure out how to solve it.
I hope someone can supply me with some guidiance or perhaps just tell me whether it's even possible or not. The complete code for the codebehind file is: -
public partial class Backend_manageImages : System.Web.UI.Page
-
{
-
ProductFactory objImages = new ProductFactory();
-
CategoryFactory objCat = new CategoryFactory();
-
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
if (!IsPostBack)
-
{
-
ddlAlbums.DataTextField = "fldName";
-
ddlAlbums.DataValueField = "fldID";
-
ddlAlbums.DataSource = objCat.getAll();
-
ddlAlbums.DataBind();
-
}
-
createTable();
-
}
-
protected void ddlAlbums_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
createTable();
-
}
-
-
protected void createTable()
-
{
-
tblImages.Controls.Clear();
-
-
TableRow tr = new TableRow();
-
foreach (DataRow image in objImages.getByCategoryID(Convert.ToInt32(ddlAlbums.SelectedValue)).Rows)
-
{
-
TableCell td = new TableCell();
-
//td.Text = "<a href=\"?ID=" + image["fldID"] + "\"><img src=\"../images/thumbs/" + image["fldFile"] + ".jpg\" alt=\"\" /></a>";
-
Image img = new Image();
-
LinkButton lnk = new LinkButton();
-
img.ImageUrl = "../images/thumbs/" + image["fldFile"] + ".jpg";
-
img.ToolTip = "Klik for at slette billedet";
-
lnk.OnClientClick = "javascript: return confirm('Delete " + image["fldFile"] + ".jpg ?');";
-
lnk.CommandArgument = image["fldID"].ToString();
-
lnk.Click += lnk_Click;
-
lnk.Controls.Add(img);
-
td.Controls.Add(lnk);
-
tr.Controls.Add(td);
-
}
-
tblImages.Controls.Add(tr);
-
}
-
-
protected void lnk_Click(object sender, EventArgs e)
-
{
-
LinkButton lnk = (LinkButton)sender;
-
int ID = Convert.ToInt32(lnk.CommandArgument);
-
DataRow image = objImages.getById(ID);
-
System.IO.File.Delete(Request.PhysicalApplicationPath + "images\\" + image["fldFile"] + ".jpg");
-
System.IO.File.Delete(Request.PhysicalApplicationPath + "images\\thumbs\\" + image["fldFile"] + ".jpg");
-
objImages.deleteProduct(ID);
-
Response.Redirect(Request.UrlReferrer.ToString());
-
}
-
}
-
5 1516
Try inserting this line - public event EventHandler Click;. HTH.
I feel a bit stupid for asking, but where do I put the line?
Line 44 should work, if I have the syntax right :)
Thanks a lot. The click event is now working - however only sometimes... If I choose a different "Album set" from my dropdown box, the click event is ignored.
After reading up on understand EventHandlers at MSDN without no sign of any epiphany I deciced to give up and use QueryStrings to switch between the album sets.
Cheers
Most likely reason is the enableautopostb ack and postback event.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: DotNetJunky |
last post by:
I have built a control that runs an on-line help system. Depending on the
category you selected via dropdownlist, it goes out and gets the child
subcategories, and if there are any, adds a new dropdownlist to the screen
for selection. This continues until there are no children, and then it
checks for a help article list based on that last selection and displays
actual articles for display.
Adding the controls and getting everything...
|
by: CodeRazor |
last post by:
Hi,
I am trying to dynamically create linkbuttons. They need an event handler,
so i can respond to the user's click.
I try to add the eventhandler on the fly, but when i click on the link, the
code does not execute, it just reloads the page.
Where am i going so wrong? i don't understand what's missing.
many thanks in advance.
|
by: Kristof Pauwels |
last post by:
Hellow, I have this peace of code from an ASP.NET page for a Mobile device,
but i have a small problem.
In this first SUB I dynmamicly create a MobileControls.Command.
I add an EventHandler to this Control
But when I click on this button, the only thing I notice is there is a post,
but the eventhandler is never fired. :-(
Is it possible that a dynmicly created control looses his event after an
PostBack??
|
by: TPS |
last post by:
I have some dynamic controls (LinkButton) that I am adding to my pages.
When the link button is clicked, I am getting an ID from the
LinkButton.CommandArguement value.
I am then using that ID to recreate some dynamic LinkButtons.
My problems is I need the CommandEventHandler to fire before the controls
are build so I can grab the ID that I will use to build the other
Linkbuttons.
|
by: DaWoE |
last post by:
Hi all,
I'm fairly new to ASP.NET. What i want to do is creat a online
registration form. On the first step is getting the users details and
the number of people he wants to register.
Based on the number of people i want to create a form where he can enter
the persons details.
For example he wants to register 3 people. Then the second step of the
registration would have to be like this :
| |
by: pd123 |
last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error "
The name 'Peter' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
Where Peter is the value entered in the textbox for firstname (fnameTBox)
I'm sure the problem is something obvious but I...
|
by: Andrew Robinson |
last post by:
I have a page that contains a number of link buttons that are used for
making selections. I load my LinkButtons during the Page_PreInit event and
they render fine but then I need to make a change to one of these
LinkButtons depending on the selection.
I am using the Command Event and passing a key in the Command.Name field.
From within this even handler, I am clearing my LinkButtons and then
re-redering and marking with a different...
|
by: Nathan Sokalski |
last post by:
I have an UpdatePanel that contains a LinkButton with a PostBackUrl. The
LinkButton is marked as a PostBackTrigger, so it does a full postback.
However, when it posts back, it goes straight to the page specified in the
PostBackUrl. I always thought (and the way I have always used it in the
past, where it worked) that it posted back to the page the button is on,
executed the stuff like Page_Load and the eventhandler for the button's
Click...
|
by: Hamayun Khan |
last post by:
Hi I have created linkbuttons dynamically using the below code
Sub createlinkbutton(ByVal commandtext As String, ByVal Cmdarg As String, ByVal pane As Panel, ByVal count As Int32)
Dim i = 0
Dim panel1 As Panel = New Panel
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |