Re: Adding EventHandler to LinkButton that I create programaticall

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

If I had another set of controls how can I go about doing it.

My page is a view photo page. Lets say there is 3 pages of 20 photo each and
a large placeholder to display a selected photo from the sets of photo. When
I move from page 1 to page 2, i had a new sets of photo display hence from
the post you were mentioning that this will not work. True enf the click
event does not fire off after the page change from 1->2.

Page 2 is reload after a selection, i.e. page 2 controls are exactly the
same as the previous page 2 components hence the event now is able to fire
off.

So how can I overcome this? Force a page reload when page renders from 1->2
or 2->1? How can i do this?Or Whats the code to write for asp.net to treat it
as a new posting?

Thanks!
JJ

"Dmytro Lapshyn [MVP]" wrote:

> Hi CodeRazor,
>
> Make sure you create exactly the same set of controls with the same IDs and
> property values upon PostBack. The whole hierarchy of controls must be
> exactly the same as it was when the page was rendered for the first time.
>
> It also matters *WHEN* you create the dynamic controls. At least they must
> be created before the PreRender phase.
> Also, make sure to add the created controls to the Page's Controls
> collection (not sure about this step, did not touch ASP .NET for more than a
> year).
>
> --
> Sincerely,
> Dmytro Lapshyn [Visual Developer - Visual C# MVP]
>
>
> "CodeRazor" <CodeRazor@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:DA57B56F-6655-4218-B1DF-34A0280F65CA@xxxxxxxxxxxxxxxx
> > 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.
> >
> > //Creating the link buttons
> > for(int i=0; i<4; i++)
> > {
> > LinkButton lbtn = new LinkButton();
> > lbtn.ID = i;
> > lbtn.Text = "Delete";
> > btn.Click += new EventHandler(lbtn_Click);
> > }
> >
> > //Event Handler
> > private void lbtn_Click(object sender, System.EventArgs e)
> > {
> > LinkButton lbtnSender = (LinkButton)sender;
> > Response.Write(lbtnSender.ID.ToString());
> > }
>
>
.



Relevant Pages

  • OT/gloat: I got an oscilloscope!
    ... figured at the very least I'd only waste $15 if it's junk. ... There's a small photo of the beast. ... And can someone give me a rundown of typical oscilloscope controls' ... I understand most of my switches and knobs now, ...
    (rec.crafts.metalworking)
  • How to Bind Image to a PictureBox
    ... I am using databinding for all the controls in my form like: ... The code above is called in the form load event. ... But of course this will not work because Photo is an image datatype in my sql server. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Strat resurrection
    ... The neck and body are now attached. ... pickups and controls have been ... pickguard was cut for a 22-fret neck, ... Serial number photo: ...
    (alt.guitar)
  • 360 degree panoramas
    ... controls after choosing a photo: ... Check out the amazing panoramas of the Grand Canyon. ...
    (alt.vacation.las-vegas)
  • RE: The View State Is Invalid for This Page and Might Be Corrupted
    ... invalid when loading them from client request. ... 2.The page added dynamic controls at runtime ... If you insert dynamic controls between existing controls. ... control's view state information is inserted into the corresponding ...
    (microsoft.public.dotnet.framework.aspnet)