Link to home
Start Free TrialLog in
Avatar of OliShim
OliShim

asked on

Setting 'OnClick' event for asp .net 'LinkButton' in a 'Repeater'

Hello,

I have a LinkButton in a asp .net repeater. I am able to set the text as desired from the databound field however I am not being able to set the onclick event.

When a user clicks the button in the repeater it needs to call a function in the codebeind and pass along a value that it is also databound.

I have tried a few different syntax and mostly I've gotten errors such 'server tag is not well formed'. The closest I've gotten is given below, however the problem is that when the repeater controls are being rendered and it is rendering the 'onclick' value it actually executes the function that should be called when the user click the button

Any help would be greatly apprecaited.
Code for the linkbuttonn:
 
<asp:LinkButton ID="LinkButton1" OnClick='<%# auditReport(DataBinder.Eval(Container.DataItem, "erid"))%>'  Text='<%# formatTitle(DataBinder.Eval(Container.DataItem, "title"))%>'  runat="server">LinkButton</asp:LinkButton>
 
 
 
and the function being called:
 
protected string auditReport(object sender)
    {
        string result = "";
        Session["ERID"] = sender.ToString();
        Response.Redirect("auditreport.aspx");
        return result;
    }

Open in new window

Avatar of aibusinesssolutions
aibusinesssolutions
Flag of United States of America image

If you are using a Repeater, you'll probably want to use the Repeater_ItemCommand function, and get the ID from there.  Could you paste the code for your repeater?  What are you binding the repeater to?
ASKER CERTIFIED SOLUTION
Avatar of jabcoco
jabcoco
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Follow jabcoco's idea.

We cant pass parameter using OnClick event handler.
You must use OnCommand.