asp.net - Unable to serialize the session state -


i tired wondering issue problem. have read many blogs , forums not able find out problem.

i using "sqlserver" mode store session.

everything working fine. whenever use search function in website, throws below error:

"unable serialize session state. in 'stateserver' , 'sqlserver' mode, asp.net serialize session state objects, , result non-serializable objects or marshalbyref objects not permitted. same restriction applies if similar serialization done custom session state store in 'custom' mode."

i assuming because of paging code have used on page. code below:

 protected void page_load(object sender, eventargs e) {     if (!ispostback)     {         string query = "select xxxxqueryxxxx";         sqldataadapter da = new sqldataadapter(query, con);         dataset ds = new dataset();         try         {             using (con)             {                 con.open();                 da.fill(ds);             }         }         catch         {             ds = null;         }                 {             if (ds != null)             {                 custompaging page = new custompaging();                 datatable dt = ds.tables[0];                 page.pagesize = 10;                 page.datasource = dt;                 page.currentpageindex = 0;                 no = 1;                 session["dt"] = dt;                 session["page"] = page;                 binddata(page, dt);                  //set these properties multi columns in datalist                 datalist2.repeatcolumns = 1;                 datalist2.repeatdirection = repeatdirection.horizontal;             }         }     } } void binddata(custompaging page, datatable dt) {     try     {         datalist2.datasource = page.dopaging;         datalist2.databind();         //datalist2.datasource = sqldatasource1;         //datalist2.databind();         lbtnpre.enabled = !page.isfirstpage; //enable / disable navigation button        // lbtnpre.cssclass = "disabledbtn";         lbtnnext.enabled = !page.islastpage;         //lbtnnext.cssclass = "disabledbtn";         lblstatus.text = navigationindicator(); //build navigation indicator          //for creating page index         datatable dt1 = new datatable();         dt1.columns.add("pageindex");         dt1.columns.add("pagetext");          (int = 0; < page.pagecount; i++)         {             datarow dr = dt1.newrow();             dr[0] = i;             dr[1] = + 1;             dt1.rows.add(dr);         }         dlpaging.datasource = dt1;         dlpaging.databind();         dlpaging.repeatcolumns = 10;         dlpaging.repeatdirection = repeatdirection.horizontal;     }     catch (exception)     {     }         {         page = null;     } } string navigationindicator() {     string str = string.empty;     //page x of y     str = convert.tostring(((custompaging)session["page"]).currentpageindex + 1) + " of " + ((custompaging)session["page"]).pagecount.tostring() + " page(s) found";     return str; } protected void lbtnpre_click(object sender, eventargs e) {     int pageindex = ((custompaging)session["page"]).currentpageindex;     if (!((custompaging)session["page"]).isfirstpage)         //decrements pageindex 1 (move previous page)         ((custompaging)session["page"]).currentpageindex -= 1;     else         ((custompaging)session["page"]).currentpageindex = pageindex;      //binds datalist new pageindex     binddata(((custompaging)session["page"]), ((datatable)session["dt"])); } protected void lbtnnext_click(object sender, eventargs e) {     int pageindex = ((custompaging)session["page"]).currentpageindex;     if (!((custompaging)session["page"]).islastpage)         //increments pageindex 1 (move next page)         ((custompaging)session["page"]).currentpageindex += 1;     else         ((custompaging)session["page"]).currentpageindex = pageindex;      //binds datalist new pageindex     binddata(((custompaging)session["page"]), ((datatable)session["dt"])); } protected void datalist2_selectedindexchanged(object sender, eventargs e) {     response.redirect("default2.aspx?partnumber=" + datalist2.datakeyfield[datalist2.selectedindex].tostring()); } protected void dlpaging_itemcommand(object source, datalistcommandeventargs e) {     if (e.commandname == "select")     {         no = int.parse(e.commandargument.tostring()) + 1;         ((custompaging)session["page"]).currentpageindex = int.parse(e.commandargument.tostring());         //binds datalist new pageindex         binddata(((custompaging)session["page"]), ((datatable)session["dt"]));      } } protected void dlpaging_itemdatabound(object sender, datalistitemeventargs e) {     linkbutton btn = (linkbutton)e.item.findcontrol("lnkbtnpaging");      if (btn.text == no.tostring())     {         btn.forecolor = system.drawing.color.maroon;         btn.font.underline = false;     }     else     {         btn.forecolor = system.drawing.color.darkcyan;         btn.font.underline = false;     } } 

i want know problem in coding , "how serialize session"? shold improve coding?

any appreciated.

thank you

i guess custom paging control not serializable. must cause of issue.

anyway, storing control in session not idea. store few serializable properties enable rebuild control (pagesize , currentpageindex), or pass them in query string example.

you use viewstate if can

about storing datatable in session, might bad idea if have lot of data , many connected users.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -