c# - asp.net // why does this value get NULL? -



c# - asp.net // why does this value get NULL? -

, have code when click button 4, want redirect link using variable querystring! utilize variable in of code when gets button class gets null!?!? next page results /..blabla?email=0. variable "pidprof"!

help, im stuck! in advance! :)

namespace displayingimages { public partial class pageview : system.web.ui.page { public string query, constr, query1, query2, query3, pidview; public int pidprof; public sqlconnection con; public void connection() { constr = configurationmanager.connectionstrings["myconnection"].tostring(); con = new sqlconnection(constr); con.open(); } protected void page_load(object sender, eventargs e) { if (!ispostback) { pidview = request.querystring["email"]; pidprof = convert.toint32(pidview); httpcontext context = httpcontext.current; searcheduser(); imagebindgrid(); postselection(); } } public void searcheduser() { connection(); string str = "select first_name,email_account,surname,id id ( id = @search )"; sqlcommand srch = new sqlcommand(str, con); srch.parameters.add("@search", sqldbtype.int).value = pidprof; sqldataadapter da = new sqldataadapter(); da.selectcommand = srch; datatable dt = new datatable(); da.fill(dt); foreach (datarow dr in dt.rows) { lblemail.text = dt.rows[0]["first_name"].tostring(); lblname.text = dt.rows[0]["email_account"].tostring(); } } /* gridview για εικονες */ public void imagebindgrid() { connection(); query = "select image imagetodb user_id= " + pidprof; sqlcommand com = new sqlcommand(query, con); sqldatareader dr = com.executereader(); dr.read(); image1.imageurl = "handler1.ashx?id_image=" + pidprof; } /* Κλασση για το post */ private void txt() { seek { if (pidprof != null) { connection(); query1 = "insert posttext (user_id,posttext) values (@user_id,@your_post)"; sqlcommand com2 = new sqlcommand(query1, con); com2.parameters.addwithvalue("@user_id", pidprof); com2.executenonquery(); postselection(); } } grab (exception ex) { } } /* Κανει select τα κειμενα και τα ανεβαζει απο την βαση στο grid */ public void postselection() { connection(); query2 = "select posttext posttext user_id= " + pidprof; sqlcommand com1 = new sqlcommand(query2, con); sqldatareader read = com1.executereader(); grdemployee7.datasource = read; grdemployee7.databind(); read.close(); } /* --------------------Κουμπι για search profile -----------------------------------*/ public void button3_click1(object sender, eventargs e) { response.redirect("~/webform7.aspx"); } protected void button4_click(object sender, eventargs e) { response.redirect("~/photoview.aspx?email=" + pidprof); } protected void button5_click(object sender, eventargs e) { response.redirect("~/default.aspx?email=" + pid); } /*logout button */ protected void button1_click(object sender, eventargs e) { system.web.security.formsauthentication.signout(); session.clear(); session.removeall(); session.abandon(); response.cache.setexpires(datetime.utcnow.addminutes(-1)); response.cache.setcacheability(httpcacheability.nocache); response.cache.setnostore(); httpcontext.current.response.addheader("cache-control", "no-cache, no-store, must-revalidate"); httpcontext.current.response.addheader("pragma", "no-cache"); httpcontext.current.response.addheader("expires", "0"); formsauthentication.signout(); httpcontext.current.user = new genericprincipal(new genericidentity(string.empty), null); response.redirect("~/logout.aspx"); } public string user_pidprof { get; set; } public datetime _myid { get; set; } public string sn { get; set; } public string ps { get; set; } public string em { get; set; } public int pid { get; set; } } }

when user clicks button, there request page, class re-instantiated. in sec request, page.ispostback true code populates pidprof never called. if move outside if block should work you.

protected void page_load(object sender, eventargs e) { pidview = request.querystring["email"]; pidprof = convert.toint32(pidview); if (!ispostback) { httpcontext context = httpcontext.current; searcheduser(); imagebindgrid(); postselection(); }

c# asp.net null request.querystring

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -