Formview inside of a User Control

Discussion in 'ASP .Net' started by Brad Baker, Jun 1, 2007.

  1. Brad Baker

    Brad Baker Guest

    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
    Brad Baker, Jun 1, 2007
    #1
    1. Advertising

  2. Brad Baker

    Brad Baker Guest

    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

    "Brad Baker" <> wrote in message
    news:%...
    >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
    >
    Brad Baker, Jun 1, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vatech1993
    Replies:
    4
    Views:
    5,665
    =?Utf-8?B?U8Opcmdpbw==?=
    Dec 11, 2004
  2. Leeor Chernov
    Replies:
    2
    Views:
    775
    Leeor Chernov
    Oct 16, 2005
  3. John R. Lewis
    Replies:
    0
    Views:
    645
    John R. Lewis
    Jan 4, 2006
  4. wikkiwikkiwaa
    Replies:
    2
    Views:
    12,532
    wikkiwikkiwaa
    Aug 9, 2006
  5. Kiran More
    Replies:
    2
    Views:
    301
    Kiran More
    Nov 14, 2006
Loading...

Share This Page