ObjectDataSource.Select()不总是射击网页提交 [英] ObjectDataSource.Select() not always firing on page postback

查看:149
本文介绍了ObjectDataSource.Select()不总是射击网页提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格:


  • 1文本框(MyTextBox)

  • 3复选框(MyCheckBox1,MyCheckBox2,MyCheckBox3)

  • 1提交按钮(MySubmitButton)

  • 1 ObjectDataSource控件(MyObjectDataSource)

  • 1的GridView(MyGridView)

我的ObjectDataSource是这样的:

My ObjectDataSource looks like this:

<asp:ObjectDataSource ID="MyObjectDataSource" runat="server"
                          SelectMethod="MySelectMethod"
                          TypeName="MyTypeName">
    <SelectParameters>
        <asp:ControlParameter Name="MyRegularString"
                              Type="String"
                              ControlID="MyTextBox"
                              PropertyName="Text" />

        <asp:Parameter Name="MySpecialString"
                       Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>

第二个参数(MySpecialString)充满这样的:

The second parameter ("MySpecialString") is filled like this:

Protected Sub MyObjectDataSource_Selecting(...) Handles MyObjectDataSource.Selecting

   Dim MySpecialString As String = "Key1=" & MyCheckBox1.Checked.ToString & ";" & _
                                   "Key2=" & MyCheckBox2.Checked.ToString & ";" & _
                                   "Key3=" & MyCheckBox3.Checked.ToString & ";"

   e.InputParameters.Item("MySpecialString") = MySpecialString

End Sub

每当我改变MyTextBox的价值和preSS MySubmitButton,MyObjectDataSource的选择方法被调用,一切工作正常。

Whenever I change the value of MyTextBox and press MySubmitButton, the select method of MyObjectDataSource is invoked and everything works OK.

但是,如果我改变我的任何复选框值(不改变MyTextBox的值)和preSS MySubmitButton,选择方法不会被调用,所以MyObjectDataSource_Selecting事件不会发生,我得到相同的结果如前

But if I change the value of any of my check boxes (without changing the value of MyTextBox) and press MySubmitButton, the select method is not invoked, thus the "MyObjectDataSource_Selecting" event doesn't take place and I get the same results as before.

我发现来解决,这是明确的调用方法MyGridView.DataBind每当MySubmitButton被点击的方法之一。这是处理这些类型的参数的最好方法?我很害怕的是,这可能会导致选择的方法被调用两次制作网页速度较慢。

One way I found to work around this was to explicitly invoke MyGridView.DataBind method whenever MySubmitButton was clicked. Is this the best way to handle these type of parameters? What I am afraid is that this may cause the select method to be called twice making the page slower.

感谢您事先的任何帮助。

Thanks in advance for any help.

CD

推荐答案

这是我终于实现了。


  1. 替换所有的ASP:用ASP ControlParameters:参数

  2. 显式调用MyGridView.DataBind方法每当MySubmitButton被点击了。

我检查和选择方法不会被调用两次这样做的时候。

I checked and the select method is not invoked twice when doing this.

这篇关于ObjectDataSource.Select()不总是射击网页提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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