开发者

Do FormViews not respond to commands issued from an ImageButton?

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜