Dynamically Created LinkButton controls and their events


J

Jules

Hi

I am dynamically creating LinkButton controls (to represent breadcrumb
trails) and am having problems with their events.

I specify the CommandName property, the Command Argument property and call
either one of these 'hookups':

lBtn.Command += new System.Web.UI.WebControls.CommandEventHandler (
this.BreadCrumb_OnClick ) ;

lBtn.Click += new System.EventHandler ( this.BreadCrumb_Click ) ;

I would have thought that this would tell the control how to parameterise
its call to __doPostBack, and in part it does, however, I get the post back
but with no event definition, the anchor tags href is like this:

href="javascript:__doPostBack('_ctl0','')

How can I properly use the Command, the CommandName and CommandArgument
properties to make this work correctly?

I do not care about the controls' state being persisted as they are created
on every hit of the page, all I want is the event handler to be called to
change server state.

Any help would be greatly appreciated!

Thanks in adv.
 
Ad

Advertisements

B

Bill Priess

Hello Jules,

In order to use the CommandName/CommandArgument functionality of the
Button/ImageButton/LinkButton, you must wire up the Command event of the
Button with a CommandEventHandler
<code>
lBtn.Command += new CommandEventHandler(lBtn_Command);
</code>

Then, you must have a target of the correct parameters:
<code>
private void lBtn_Command(object sender, CommandEventArgs e)
{
//Here is where the CommandName/CommandArguments come into play.
Response.Write(e.CommandName + "<br>");
Response.Write((string)e.CommandArgument + "<br>");
}
</code>

Now, believe it or not, the CommandName/CommandArgument details have nothing
to do with the __doPostBack JS method. The __doPostBack JS method just
specifies to ASP.NET what control has triggered the post back.

Anyhow, HTH,

Bill Priess
eCircle Software, LLC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top