?
Solved

C# and this.Events.AddHandler

Posted on 2004-08-28
2
Medium Priority
?
6,854 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 1500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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