asp.net - EnableViewState causing loss of value -
using vb.net 4.5 , telerik 2017.2.711.45 (q2) trying radgrid filter expressions , public string variable persist across postbacks.
with enableviewstate=false
, radgrid filter expressions do not persist through postback, public string variable (stringvar) does persist.
when set enableviewstate=true
filter expressions in radgrid do persist, causes stringvar not persist.
from understanding of viewstate, makes no sense setting enableviewstate=true
cause stringvar not persist across postbacks. love know why occurring , resolve this.
edit: highlighted line error thrown because reporttitle no longer has value.
partial class displayxslgrid public reporttitle string public reportsdb reportdatabase protected sub page_load(byval sender object, byval e system.eventargs) handles me.load page.enableviewstate = true reports = new reportdatabase.global_functions(system.web.httpcontext.current) end sub protected sub radgrid1_needdatasource(sender object, e telerik.web.ui.gridneeddatasourceeventargs) handles radgrid1.needdatasource call bindradgrid1() end sub protected sub radgrid1_itemcommand(byval source object, byval e telerik.web.ui.gridcommandeventargs) handles radgrid1.itemcommand dim strreporttitle string select case e.commandname case radgrid.exporttoexcelcommandname, radgrid.exporttowordcommandname, radgrid.exporttocsvcommandname
strreporttitle = reporttitle.trim
end select end sub public sub bindradgrid1() dim strreporttitle string dim dt datatable = nothing reporttitle = dt.rows(0).item("reporttitle") strreporttitle = dt.rows(0).item("reporttitle").tostring 'radgrid1 data source gets set here along other stuff end sub end class
using view state normal, , telerik controls need preserve values across post-backs. public string property on page class should not persist, , should set/calculated every time. if absolutely need persist, save value in hidden server control, or have in querystring of url.
Comments
Post a Comment