ASP.Net 表单数据绑定问题
我知道这个论坛上有类似的问题,但解决方案对我来说并没有真正起作用。 我正在使用来自几个不同数据源的字段填充表单控件,并且数据显示得很好。
我有一个 ImageButton
控件,它有一个 OnClick
事件集,用于从表单中获取所有数据。 不幸的是,当我单击按钮时,似乎页面首先重新加载,然后执行 OnClick
调用。 手动输入或硬编码的数据似乎可以从输入的控件中很好地提取,但从数据源提取的任何内容都无法读取。 有任何想法吗。 这是我已经工作了 6 个月的项目的最后一个障碍。
I know there is a similar problem on this forum, but the solutions did not really work for me. I am populating form controls with fields from a few different data sources, and the data shows up great.
I have an ImageButton
control, which has an OnClick
Event set to grab all of the data from the form. Unfortunately, when I click the button, it seems as though the page is reloading first, and THEN is executes the OnClick
call. The data that was hand-entered, or hard-coded seems to be pulled fine from the controls it was entered in, but anything that was pulled from a datasource is not able to be read. Any ideas. this is the last hurdle in a project that I have been working on for 6 months.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你是在谈论下拉菜单还是网格视图? 您何时在页面加载时绑定数据?
好的设计会让您在页面加载时绑定数据,但仅限于
否则它将重新绑定每个页面加载。 如果它没有重新加载,您可以从这些控件中获取选定的值(如果这就是您想要的值)。
另一种方法是使用数据源对象在 aspx 页面中设置数据源和数据绑定。 这会自动执行上述操作。
Are you talking about drop downs or gridviews? When are you binding data, on page load?
Good design will have you bind your data upon page load but only in
Otherwise it will rebind every page load. If its not reloading you can get selected values from those controls if thats what your looking for.
An alternative is to set your data source and databind in your aspx page with a datasource object. That automates the above automatically.
您是否在控件上启用了视图状态? 发布代码示例将有助于解决您的问题。
Have you enabled viewstate on your controls? Posting code samples would go a long way to helping solve your issue.
当您单击 ASP.NET 中的底部时,首先会发生所有页面事件,如
Page_Load
和 ...,然后事件发生(在本例中为Click
)。但是因为所有内容都会再次加载,我认为您的代码中有一个用于绑定数据的
!isPostback
,您应该删除它以便每次都能获取数据。或者,如果这不是解决方案,请发布一些代码和问题的更多描述
When you click on a bottom in asp.net at first all the page Events take place like
Page_Load
and ... and then the event happens ( in this caseClick
).But because everything is loading again, I think that you have a
!isPostback
in your code that you use to bind the data, you should remove that in order to get your data every time.Or if it is not the solution please post some code and more description for the problem
实际上,它是隐藏字段、下拉菜单、标签和文本字段。 我只是尝试在
init
和load
中进行绑定,但没有骰子。 当我尝试仅将其绑定在!isPostBack
上时,没有任何字段显示。我认为主要问题之一是我获得的数据集来自对 API 的方法调用。 我收到的数据很好,但它是以编程方式输入的,然后我也必须以编程方式进行所有控制设置。 您想查看想法代码吗? 谢谢大家帮忙,今天没人上班!
贾森
Actually, it is hiddenfields, dropdowns, labels, and textfields. I just tried doing the binding in the
init
, and theload
, but no dice. When I tried binding it on!isPostBack
only, none of the fields showed up.I think one of the main problems is that the dataset I am getting is from a method call to an API. I receive the data fine, but it comes in programmatically, then I have to do all of the control-setting programmatically as well. Would you like to see the code for ideas? Thank you for helping, no one is working today!
Jason