views:

28

answers:

3

I am using ImageButtons in place of LinkButtons in a FormView to issue New/Edit/Delete/Cancel commands, but they don't seem to have an effect on the FormView.

The ImageButtons will cause a postback but the FormView mode doesn't change from the current mode.

I'm sure the ImageButtons were working at one point, but I've been busy with other pages for a while. The only thing that's changed between now and then are some patches I installed in Visual Studio.

I haven't been able to find any information related to this issue other than this: http://www.codeproject.com/KB/webforms/TamingTheFormView.aspx In that article there's an onclick method for an ImageButton that's used to change the FormView mode.

Would that be the only way to use ImageButtons instead of LinkButtons in a FormView?

Here are some code fragments:

<asp:FormView ID="CourseFormView" runat="server" DataKeyNames="CourseCode" 
    DataSourceID="CourseSqlDataSource" ondatabound="CourseFormView_DataBound">
    <ItemTemplate>
        <table>...</table>
        <asp:ImageButton ID="EditCourseImageButton" CssClass="image_button"
            runat="server" CommandName="Edit"
            ImageUrl="~/images/icons/pencil.png" />
     </ItemTemplate>
</asp:FormView>

Codebehind:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["code"] == null ||
                Request.QueryString["code"] == "")
        {
            CourseFormView.ChangeMode(FormViewMode.Insert);
            CourseCodeTitleLabel.Visible = false;
            CourseTitleTitleLabel.Text = "Add a new course...";
            SchedulePanel.Visible = false;
        }

    }

There is no other code for processing the buttons. I had created some empty event handlers for the FormView to see what was happening - ModeChanging, ModeChanged, and ItemCommand. None of them were being called when I clicked on the ImageButton, but everything worked fine if I used a LinkButton.

I'm not doing anything complicated - I just want the FormView to respond to basic ImageButton commands.

A: 

Hey,

To test, the form should have a Command or ItemCommand event that will fire when the command is clicked on... attach to it and test to see that it fires, and that the e.CommandName is edit... (I think there is a command param, but am not 100% sure).

That will at least tell us if that is working... if that fires, you can at least programmably change it to edit mode.

HTH.

Brian
I indicated (in my edited post) that I added event handlers on the formview for ModeChanging, ModeChanged, and ItemCommand. None were fired.
Duke
A: 

Use command field instead of seperate image button like..

  <asp:CommandField ButtonType="Image" UpdateText="Update Text.."  ShowEditButton="True" >
       <ItemStyle HorizontalAlign="Center" />
  </asp:CommandField>
Muhammad Akhtar
asp:CommandField doesn't appear to be a valid tag in FormView templates.
Duke
A: 

The issue was that I was calling Page.DataBind() in my Master page. I'm not sure how that interferes, but I removed the call and recoded the page so it's not necessary.

Duke