Click here to Skip to main content
15,881,757 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: DropDownList databinding error Pin
sudharsong11-Jul-06 19:57
sudharsong11-Jul-06 19:57 
QuestionStatic Variable Vs. Application Object stored variable Pin
Abhinav Nigam10-Jul-06 23:42
Abhinav Nigam10-Jul-06 23:42 
AnswerRe: Static Variable Vs. Application Object stored variable Pin
IamMohan11-Jul-06 0:49
IamMohan11-Jul-06 0:49 
QuestionCreate run time asp.net page Pin
Parwej Ahamad10-Jul-06 23:36
professionalParwej Ahamad10-Jul-06 23:36 
AnswerRe: Create run time asp.net page Pin
Guffa11-Jul-06 0:03
Guffa11-Jul-06 0:03 
AnswerRe: Create run time asp.net page Pin
Saifi Hasan11-Jul-06 2:35
Saifi Hasan11-Jul-06 2:35 
Questionhow to restrict row and column size in Excelsheet Pin
Bridzet10-Jul-06 23:09
Bridzet10-Jul-06 23:09 
QuestionEvents not responding after re-creation of dynamically created webcontrols [modified] Pin
oxiroxt10-Jul-06 22:37
oxiroxt10-Jul-06 22:37 
Hi everyone,

I have a situation where I must add ImageButtons dynamically on a page. This I managed to do, but I need them to respond to the Click event and they won't.

Here's a snippet which represents what I'm doing:
public partial class _Default : System.Web.UI.Page
{
    ArrayList imagenes = new ArrayList();

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            ImageButton ib3 = new ImageButton();
            ib3.ID = "ib3";
            ib3.ImageUrl = "Puesta de sol.jpg";
            ib3.Click += new ImageClickEventHandler(ImageButton_Click);
            ib3.Width = new Unit(100, UnitType.Pixel);
            ib3.Height = new Unit(100, UnitType.Pixel);
            form1.Controls.Add(ib3);
            imagenes.Add(ib3);

            Session["Imagenes"] = imagenes;
        }
        else
        {
            imagenes = (ArrayList)Session["Imagenes"];
            foreach (ImageButton ib in imagenes)
                form1.Controls.Add(ib);
        }
    }

    protected void ImageButton_Click(object sender, ImageClickEventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(GetType(), null, "alert('HEY');", true);
    }
}


After clicking on the ImageButton, the page reloads, enters the Else clause, the ImageButton is restored, but it won't enter the Click handler.
Also, I tried setting the handler manually inside the Else clause after the control has been added to the form but it won't enter the handler either.

My guess is this is happening because asp.net is actually assigning the handler, but the call to the handler is simply 'lost' during the restoration of the controls since it appears asp.net expects to fire events for 'static' controls only.

I've checked that when a Click event is fired for a 'static' ImageButton, the execution path goes through the Page_Load first and ends into the handler. That's why i re-create the control in the Else clause in Page_Load.

It's not as important for me to get every delegate for each control restored(which i guess it actually is) and working, as it is getting all of them getting into one handler as expected, since I'll possibly assing all of them the same handler.

Thanks a lot in advance for any help you could provide,

Oxi

-- modified at 4:52 Tuesday 11th July, 2006
AnswerRe: Events not responding after re-creation of dynamically created webcontrols Pin
oxiroxt10-Jul-06 23:12
oxiroxt10-Jul-06 23:12 
QuestionPrint Headers of Datagrid on Multiple Pages Pin
varun_khanna1710-Jul-06 22:15
varun_khanna1710-Jul-06 22:15 
QuestionScreen Capture Pin
Jeeva Mary Varghese10-Jul-06 21:37
Jeeva Mary Varghese10-Jul-06 21:37 
AnswerRe: Screen Capture Pin
Guffa11-Jul-06 0:07
Guffa11-Jul-06 0:07 
GeneralRe: Screen Capture Pin
Jeeva Mary Varghese11-Jul-06 0:21
Jeeva Mary Varghese11-Jul-06 0:21 
AnswerRe: Screen Capture Pin
Guffa11-Jul-06 9:41
Guffa11-Jul-06 9:41 
GeneralRe: Screen Capture Pin
Jeeva Mary Varghese11-Jul-06 23:16
Jeeva Mary Varghese11-Jul-06 23:16 
QuestionInsert command Pin
kirthikirthi10-Jul-06 20:42
kirthikirthi10-Jul-06 20:42 
AnswerRe: Insert command Pin
Guffa10-Jul-06 23:39
Guffa10-Jul-06 23:39 
GeneralRe: Insert command Pin
kirthikirthi11-Jul-06 0:48
kirthikirthi11-Jul-06 0:48 
GeneralRe: Insert command Pin
eggsovereasy11-Jul-06 9:01
eggsovereasy11-Jul-06 9:01 
QuestionInterop Error while including Microsoft outlook dll in dot net 2005 Pin
aaraaayen10-Jul-06 20:36
aaraaayen10-Jul-06 20:36 
Questionauto upload/export of a downloaded CSV file to SQLSERVER on the server Pin
amitcoder8310-Jul-06 19:55
amitcoder8310-Jul-06 19:55 
AnswerRe: auto upload/export of a downloaded CSV file to SQLSERVER on the server Pin
Saifi Hasan11-Jul-06 2:51
Saifi Hasan11-Jul-06 2:51 
Questionsave image in database and show all images in control from database [modified] Pin
srinandan..10-Jul-06 19:52
srinandan..10-Jul-06 19:52 
AnswerRe: save image in database and show all images in control from database Pin
Paul Conrad25-Jul-06 9:23
professionalPaul Conrad25-Jul-06 9:23 
QuestionInsert comment in Excel sheet with Asp.net Pin
mhemant10-Jul-06 19:50
mhemant10-Jul-06 19:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.