Solved

C# and this.Events.AddHandler

Posted on 2004-08-28
2
6,801 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Reading the Web.Config using IIS 7.5? 4 49
asp.net input html code have it display the content 2 23
asp.net web application 3 32
Where is this file? 3 26
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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