views:

116

answers:

1

Hello all,

I am using c#.net.

I am trying to create a LinkButton within the code-behind, when I debug my code I recieve no errors, however its not accessing the EventArg attached to the button, it does however refresh the page. What am I doing wrong?

Button Code

LinkButton myLinkButton = new LinkButton();
myLinkButton.ID = appointment.appID.ToString();
myLinkButton.CommandArgument = appointment.appID.ToString();
myLinkButton.Command += new CommandEventHandler(ViewClick);
myLinkButton.CommandName = appointment.appID.ToString();
myLinkButton.Text = appointment.contactName

Used to style button

string divLook = "height:" + divHeight + "em";

Button is then added to a panel

Panel p = new Panel();
p.Style.Add("linkStyle", divLook);
p.CssClass = "standardLink";
p.Controls.Add(myLinkButton);
dataCell.Controls.Add(p);  



protected void ViewClick(object sender, CommandEventArgs e)
{
      var appointmentId = Convert.ToInt32(e.CommandArgument);
      Debug.Write("Are you even getting in here");
}

Thanks in advance for any help.

Clare

A: 

Everything looks legit. I would recommend viewing the source of the generated page and looking at the ID that the link button is getting. It may be duped on the page.

Demetri
This is what it is outputting to screen: <a id="ctl00_BodyContent_14" href="javascript:__doPostBack('ctl00$BodyContent$14','')">1 1 (Triple Birth)</a><a id="ctl00_BodyContent_15" href="javascript:__doPostBack('ctl00$BodyContent$15','')">Add Forename Add Surname (Single Birth by Declaration )</a>
ClareBear
Make sure your web.config has <compilation debug="true"> and when you run the project that run with debugging is enabled. Also, set a breakpoint in the PageLoad methods to ensure debugging is working as intended.
Demetri