Formview inside of a User Control

B

Brad Baker

I have created a usercontrol (ascx file) which contains a formview, inside
of the formview I have an EditItemTemplate and an ItemTemplate. Both the
EditItemTemplate and ItemTemplate have link buttons which call some code to
changed the formview mode from Edit to ReadOnly or vice versa. When I run
the code though and click the link buttons, the formview doesn't switch
modes (the page reloads the mode just doesn't change)

Here is the code which switches modes:

protected void view_linkbutton_click(object sender, EventArgs e)
{
formview.ChangeMode(FormViewMode.ReadOnly);
}

protected void edit_linkbutton_click(object sender, EventArgs e)
{
formview.ChangeMode(FormViewMode.Edit);
}

Here is an excerpt of the formview:

<asp:FormView ID="formview" runat="server"
DataSourceID="formview_datasource" Width="100%" DefaultMode="ReadOnly">
<EditItemTemplate>
<table>
<td> Mode:</td>
<td><asp:LinkButton ID="ViewLinkButton" runat="server"
OnClick="view_linkbutton_click">View</asp:LinkButton>
|
<asp:LinkButton ID="EditLinkButton" runat="server"
OnClick="edit_linkbutton_click">Edit</asp:LinkButton></td>
</EditItemTemplate>
<ItemTemplate>
<table>
<td> Mode:</td>
<td><asp:LinkButton ID="ViewLinkButton" runat="server"
OnClick="view_linkbutton_click">View</asp:LinkButton>
|
<asp:LinkButton ID="EditLinkButton" runat="server"
OnClick="edit_linkbutton_click">Edit</asp:LinkButton></td>
</ItemTemplate>

This code previously worked before I moved it from default.aspx to a user
control (ascx) file. So I can't seem to figure out why its stopped working.
Do I need to reference the formview differently now that I moved it to the
ascx file?

Thanks
Brad
 
B

Brad Baker

Alright - i'm just a moron. I had a simple typo in some related code (not
above) which was causing the problem. Thank you for anyone that looked at
this :)

Brad
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top