I have a Grid View to which I've using an Object Data Soure as the data source.
The Object Data Source is taking in parameters from a Text Box and Drop Down List which is then passed into the stored procedure.
There is also a button called Search which can be used to force a refresh on the Grid View by providing/changing values in the Text Box and/or Drop Down List.
Is there anyway to prevent this action while still using the Object Data Source?
When you assign a Data Source ID on the Grid View, the grid will automatically bind to the Object Data Source. I also tried to set the Data Source property, instead of the Data Source ID, and then manually binding it but I'd have to work manually code in the paging too then which defeats the purposed using the Object Data Source control.
You can simply omit that property on the Grid View and wait until the Search button's click event to assign it. The problem is that every time any parameter used for Object Data Source is changed the ODS performs a "Data Bind". The Object Data Source will only do a "Data Bind" when you change the values on the Hidden Fields.
That's correct, remove it from the aspx page and wait until your click event to assign it in the codebehind. So you can change the values on the Text Box and Drop Down List, and when you want a "Data Bind" you only need to copy the values to the Hidden Fields.
NET forums is how to deal with exceptions like The Grid View 'Grid View1' fired event Row Editing which wasn't handled.
The Grid View 'Grid View1' fired event Page Index Changing which wasn't handled.The Grid View 'Grid View1' fired event Sorting which wasn't handled.It would help to see your Grid View definition as well as your Data Source. @derek-hunziker The issue with that approach is I need the Grid View to be bound at page load too. Here is a code sample I made for another question: Q11874496Web App.7z Thanks @Hailton for your suggestion.I'm feeling slightly reluctant to use anymore hidden fields since I've already used quite a bit.However if bad comes to worse I'll probably use this, afterall one could argue how much of a difference is an additional couple of hidden fields going to make... A drawback is that a new page_load that is not caused by btn Search_Click will reset the private variable's value.If you want it to be persistent you should use a hidden field as proposed or save it to viewstate.