Re: How do you set up the OnClick with ASP 2.0 ?
- From: senfo <enceladus311@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 04 Nov 2006 20:06:37 -0500
guy wrote:
In my 1.1 project, I was creating dynamically a LinkButton, and stored
it into a Table.Row.Cell.Controls(). I was adding an MyOnClick handler
to the Click property. I was doing this during the Load phase. It
worked. Porting my code to 2.0, the Click event do not work anymore. It
is not generated in the intermediate c# files created by the
pre-compiling.
After some investiguation on the net, it appears that one must connect
a Click handler during the OnInit phase. But in that phase the
ViewState is empty, so I cannot re-create my controls. So this works
only if the control was on the postback page. Other posts seems to
indicate that one must now use the AddAttributes to generate an
"OnClick" attribute, calling a javascript, which will handle the detail
of the submit if I want a post back.
Is this the best way to generate a button click event handler, on a
dynamically created control ?
So many steps...
Maybe I don't understand your problem, but the following code works fine for me:
protected override void CreateChildControls()
{
LinkButton btn = new LinkButton();
btn.Text = "Click Me";
btn.Attributes.Add("onclick", "alert('Testing');");
this.form1.Controls.Add(btn);
}
I just placed that in my Default.aspx.cs file and it works just fine.
Am I missing something?
Hope that helps,
--
Sean
.
- References:
- Prev by Date: Re: How do you set up the OnClick with ASP 2.0 ?
- Next by Date: Re: [Atlas Beta1] how to manually trigger an async postback
- Previous by thread: Re: How do you set up the OnClick with ASP 2.0 ?
- Next by thread: Re: How do you set up the OnClick with ASP 2.0 ?
- Index(es):
Relevant Pages
|