如何避免出现InvalidOperationException设置在ASPX内容defaultbutton时 [英] How to avoid InvalidOperationException when setting the defaultbutton in ASPX content

查看:151
本文介绍了如何避免出现InvalidOperationException设置在ASPX内容defaultbutton时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的ASPX页面设置默认按钮。我有一个母版页这样的形式是存在的。我有在认为举办多个文本框,下拉菜单和其他投入的表格内容页的面板。该表的最后一行持有一些按钮,其中一个我想成为默认按钮。之后做一些研究,我曾尝试没有成功以下。

I am trying to set a default button in my ASPX page. I have a master page so the form is there. I have a panel in the content page that holds a table that organizes a number of textboxes, dropdowns and other inputs. The last row of the table holds some buttons, one of which I want to be the default button. After doing some research, I have tried the following with no success.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
       pnlHolder.DefaultButton = cmdSearchJob.ClientID

我也试过

pnlHolder.DefaultButton = cmdSearchJob.UniqueID

Dim cmdDef As Button = pnlHolder.FindControl("cmdSearchJob")
pnlHolder.DefaultButton = cmdDef.UniqueID

但都扔在例外的pnlHolderdefaultButton必须类型IButtonControl的控件的ID。

我已经看到一些JavaScript的解决方案,但希望只是能够设置defaultButton为面板。

I have seen some Javascript solutions, but was hoping to just be able to set the defaultButton for the panel.

推荐答案

终于发现那是什么。尝试添加另一个按钮,没有CSS等,只是弹出一个用于测试的javacsript警报()。能够设置为默认的按钮时,它是表外。由于提交按钮在表中的一系列的按钮中的一个(不是一个非常pretty用户界面,但用户要求和所有的),我用这额外的按钮,并设置其样式为display:none和使用它调用同样的子程序后面的code。

Finally found what it was. Tried adding another button with no CSS, etc. that just popped up a javacsript alert() for testing. Was able to set that as the default button when it was outside the table. As the submit button is one of a series of buttons (not a very pretty UI, but user requirements and all that) in the table, I used this additional button and set its style to display:none and have it call the same subroutine in the code behind.

所以,简单的答案,这是没有看到它在表中。

So, short answer, it wasn't seeing it in the table.

谢谢大家对您的输入。

我仍然不知道为什么它不会设置按钮。

I still have no idea why it wouldn't set the button.

这篇关于如何避免出现InvalidOperationException设置在ASPX内容defaultbutton时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆