asp.net - Response.Redirect(Request.Url.AbsoluteURI) Clearing all user entries -
i have page user fills in text boxes saved sql database using submit button. page contains button allows them upload attachments. if user uploads attachment before clicking submit button save other data, values in text boxes cleared once upload routine executes response.redirect(request.url.absoluteuri). have tried saving values want restore session, don't seem able restore them. debugger shows there, once response.redirect executed, next lines never executed. i'm brand new asp.net, may missing obvious. here code upload procedure:
protected sub upload(sender object, e eventargs) handles btnupload.click session("phone") = txtphone.text session("name") = txtname.text session("email") = txtemail.text session("startdate") = txtstartdate.text session("enddate") = txtenddate.text session("subject") = txtsubject.text session("description") = txtdescription.value dim filename string = path.getfilename(fileupload1.postedfile.filename) dim contenttype string = fileupload1.postedfile.contenttype using fs stream = fileupload1.postedfile.inputstream using br new binaryreader(fs) dim bytes byte() = br.readbytes(fs.length) dim constr string = configurationmanager.connectionstrings("engineeringrequestsconnectionstring").connectionstring using con new sqlconnection(constr) dim query string = "insert attachments values (@id, @name, @contenttype, @data)" using cmd new sqlcommand(query) cmd.connection = con cmd.parameters.add("@id", sqldbtype.int).value = nextid cmd.parameters.add("@name", sqldbtype.varchar).value = filename cmd.parameters.add("@contenttype", sqldbtype.nvarchar).value = contenttype cmd.parameters.add("@data", sqldbtype.varbinary).value = bytes con.open() cmd.executenonquery() con.close() end using end using end using end using hasupload = true response.redirect(httpcontext.current.request.url.absoluteuri) bindgrid() end sub
the bindgrid() procedure attempts restore values session never gets executed.
if hasupload txtphone.text = ctype(session("phone"), string) txtname.text = ctype(session("name"), string) txtstartdate.text = ctype(session("startdate"), string) end if
this first post on so. apologize if in advance if not clear enough.
if new asp.net webforms it's worth checking out page lifecycle dictates order in events fired when page loaded. issue taking user page page b expecting them see results on page a.
in method
protected sub upload(sender object, e eventargs) handles btnupload.click .. skip .. response.redirect(httpcontext.current.request.url.absoluteuri) bindgrid()
when call response.redirect()
browser redirect new page (e.g. -> b), start page lifecycle on again, happens after response.redirect()
won't rendered. think confusing you redirecting (a -> a), still cause page reloaded.
one option call bindgrid()
, reload data session in 1 of page load events, or remove call response.redirect()
, instead leave page as-is.
Comments
Post a Comment