FormView 是否不响应从 ImageButton 发出的命令?
我在 FormView 中使用 ImageButtons 代替 LinkButtons 来发出新建/编辑/删除/取消命令,但它们似乎对 FormView 没有影响。
ImageButtons 将导致回发,但 FormView 模式不会从当前模式更改。
我确信 ImageButtons 在某个时刻可以工作,但我已经忙于其他页面一段时间了。从现在到那时,唯一发生变化的是我在 Visual Studio 中安装的一些补丁。
除此之外,我无法找到与此问题相关的任何信息: http: //www.codeproject.com/KB/webforms/TamingTheFormView.aspx 在那篇文章中,有一个 ImageButton 的 onclick 方法,用于更改 FormView 模式。
这是在 FormView 中使用 ImageButtons 而不是 LinkButtons 的唯一方法吗?
以下是一些代码片段:
<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>
代码隐藏:
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;
}
}
没有其他代码用于处理按钮。我为 FormView 创建了一些空的事件处理程序来查看发生了什么 - ModeChanging、ModeChanged 和 ItemCommand。当我单击 ImageButton 时,它们都没有被调用,但如果我使用 LinkButton,则一切正常。
我没有做任何复杂的事情 - 我只是想让 FormView 响应基本的 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了测试,表单应该有一个 Command 或 ItemCommand 事件,当单击该命令时该事件将触发...附加到它并测试它是否触发,并且 e.CommandName 是编辑...(我认为有是一个命令参数,但我不是 100% 确定)。
这至少会告诉我们这是否有效......如果触发,您至少可以通过编程将其更改为编辑模式。
HTH。
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.
问题是我在我的母版页中调用 Page.DataBind() 。我不确定这会如何干扰,但我删除了调用并重新编码了页面,因此没有必要。
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.