asp:Button inside SharePoint Dataview Rows with onclick event does not call C# function. Pull it out of Dataview and works fine

StackOverflow https://stackoverflow.com/questions/3716271

Question

asp:Button inside SharePoint Dataview Rows with onclick event does not call C# function. Pull it out of Dataview and works fine.

I have a ASP.NET Button I've placed inside a SharePoint DataView's rows with an onclick event pointing to C# function block inside my page. The page refreshes when I click on them, but it's not hitting that code block. If I move the button to outside the dataview and make the ID fixed, the code works beautifully. what's up with that?

the button in the Dataview:

<asp:Button runat="server" Text="Delete" id="Delete{@ID}" CommandArgument="{@FileRef}" OnClick="DeleteDoc"/>

my C# onclick handler (inline C# on the page)

void DeleteDoc(object sender, EventArgs e){sendmail("DeleteDoc");Button b = sender as button;.. more code

This is all inline code and I'm working from SharePoint Designer. Not sure how I can troubleshoot this.

Am I missing something here, maybe I need to add an Itemtemplate or something like we need to in a ASP.NET gridview controls?

Thanks.

Was it helpful?

Solution

IIRc, you need to use Actions, not events.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top