Solved

C# and this.Events.AddHandler

Posted on 2004-08-28
2
6,832 Views
Last Modified: 2008-01-09
I am writing a program that adds images to the web page at runtime
by using the following commands

(Namespace : System.Web.UI.Page)

HtmlImage h=new HtmlImage();
h.Attributes.Add("style","position:absolute; left:150; top:200");
h.Src="bb/00000.jpg";
this.Controls.Add(h);

When the user clicks on the image i added i want to redirect the page to www.x.com

I have written the function below to handle this event, but i need to add an event handler to
the image "h" so that the function is executed

private void h_Click(object sender, System.EventArgs e)
{
 Response.Redirect("www.x.com");
}

this.Events.AddHandler(...............);

Please Can you tell me exactly what parameters to pass to the above procedure

Thanx.
0
Comment
Question by:BrettLombardo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 500 total points
ID: 11924219
Got a better idea:

HtmlImage h = new HtmlImage();
h.Attributes.Add("style","position:absolute; left:150; top:200");
h.ATtributes.Add("onclick", "javascript:window.location.href=\"http://www.x.com\";");
h.Src="bb/00000.jpg";
this.Controls.Add(h);

This will accomplish exactly the same thing, unless you need to something else before calling Response.Redirect().

John
0
 
LVL 8

Expert Comment

by:shovavnik
ID: 11924790
To capture events, you should use the asp WebControls instead of the HtmlControls.

Try using an ImageButton, which has an OnClick event.



(Also, a side note, avoid setting the style attribute explicitly.  You can use the Style property of the control instead to add name/value paris of styles to the controls style collection.  Even better, use css classes, so you don't need to recompile your code just to change the style of an image.)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question