Pls somebody help me with viewsate. Suppose i have created two forms. First form contains First name and Last name and one button called NEXT. And Second form contain two fields and two button like Back and Save. While i am entering some value in form1 pressing one NEXT button and redirecting to second page. There when i am pressing Back button from second page it should come to first page whichever data i filled should exists, but in my case its not showing only empty form i can see when i am pressing on back button.
For this i have used viewstate mechanism. in page directory i have set enableviewstate=true.
postbackurl in both the button. Pls somebody help me what is wrong with me.
Thanks,
Sumit
Viewstate won't carry information from one WebForm to another. It only carries information across postbacks on the same WebForm.
You want to use another method, like SessionState, to carry information from the first page to the second page. Otherwise, you could combine all your inputs on the same page and separate them into multiple steps using something like the ASP.NET Wizard control.
David Lively's suggestions of cookie or database solutions are good, too.
ViewState will help you ship data between views/postbacks of the same page, but isn't really going to help you when moving data between separate pages.
In your first page, populate a cookie or database with your form fields. Any form can then update the cookie, delete it, or what have you.
You can call a javascript function that is doing a "real" back. Maybe I am missing something but this is what I would do.
onClick="history.go(-1)"
When a page is called from some other page it is not a post back, it is viewed as if it is a first time call... When a page is called from the same page then it is termed as a post back... View state or in the sense control values are maintained only during post back, and gets reseted to form values during first time call...
This is the reason behind why you are not seeing the values of the controls.
As others suggested, try using session or cookies and the best option would be Wizard.
Related
I want a table in the page to be filled with the data that corresponds with a picture on the page. The user has to click the picture that he wants more information about. The way i have done this is making the images into image-Buttons, Make the button store a session variable and redirect back to the same page, then the session variable is read and used to fill the table. Is it possible to get the same results without reloading the page?
From your question I can guess that you're using webforms.
Yes, it's possible in ASP.NET, take a look at UpdatePanel control, it does exactly what you want.
I am sure this has been asked before, but all of the links I find have to do with posting data to a popup page.
In my case I am trying to return two values/variables from the popup page back to the orginal page.
My effort thus far was to create two session variables in the popup page code behind, and then refresh the first page when the popup was closed. I'm not sure how best to do this. I do not want a fullpage refresh, I just want two textboxes to show the values of each of the session variables.
If I use the postback URL on my close button, my codebehind never fires to populate my session variables and it opens another instance of my calling page.
If someone has a link or tutorial to show this I would be very greatful.
Thank you,
Firstly I don't understand that returning value to the parent does need a session variable ?
Well you can pass the values to the parent in either json or XML or array, all you need is a piece of JavaScript which is window.parent and you can call the JavaScript method on the parent.
If your requirement is to save it in server session you can do whatever you are doing currently
I found these links which answered my question allowing me to solve this problem with ASP/VB not JavaScript, JSON or XML.
http://asp-net.wonderhowto.com/how-to/implement-cross-page-postback-asp-net-214606/
http://www.asp.net/web-forms/videos/how-do-i/how-do-i-implement-a-cross-page-postback-in-aspnet
I'm trying to describe it in as few steps as possible:
I have Page1.aspx with lot of controls, and Preview and Save button among those. I also have Page2.aspx that is the redirection target of a Preview Button click.
Since I need all the controls selections from Page1 to draw a preview on Page2 the redirection is done with setting Preview's PostBackUrl.
I also must have preview shown on a new tab or window so I used onClientClick="aspnetForm.target='_blank'" for Preview button definition.
Save button-click callback, after storing data to a database does redirection to some Page0.aspx (initial list of reports - the subject of the code)
Preview button works fine - a preview renders in a new tab, but when I go to the old tab and click on Save, I see from debugger, that firstly Page2.aspx(?) and secondly Page1.aspx are loaded. Then all the data is stored in the db, but though Page0 redirection is executed Page1.aspx stays loaded in the browser.
I have no idea what processes are behind this. Could one who knows give me an insight? Or if you consider my approach impossible to implement give some idea how to do the same?
If it's of importance, everything on the Page1 is located in an update panel.
Thank you very much for replying
In ASP.NET there are basically zero (0) circumstances in which you will ever send form data from one page to another. Although what exactly you are trying to accomplish is vague, you can consider some of the following:
Isolate unique operations/systems to a single page. If you have something like a User Profile, don't have three different aspx pages; just use a single page for the user or admin to manage that data / functions. Postback events are your friend.
Understand the difference between ViewState and traditional form data. I'm guessing that if you're trying to post form data from one page to another, you probably don't understand the point of ViewState. Using a single page to maintain temporary data that the user is currently working with is a great use for ViewState. If you want the data to appear on another page then you need to consider the data from the previous page as final and thus should be saved to a database or some other medium.
These are just some general guidelines because there is no exact answer to your problem without saying something generic like "You're doing it wrong." I would recommend starting by never again trying to post form data from one aspx page to another.
I have a page in asp.net by clicking on the grid in the page it takes me to the detail page,on this page i have a back button (not browser back) by clicking on the button it takes me again to the search page.
i want to see the page with changes which i have made before coming to the detail page,also i want to disable back button of browser.
i dont want to use session variable or viewstate variable.
is there any property for this scenario.
yours sincerely
Talha khan
You can't disable the browser back button. End of story. Sorry.
What changes are you making to the grid, where is it getting it's data from? You could use a cookie to store the previous pages' state if you don't want to use session or viewstate.
If the the amount of data you need to track is relatively small (in your case this would probably be a search query) you can use query string to pass the state to the detail page (which can be later passed back to the search page).
You can also use browser cookies to persist the state but I wouldn't do that (at least because they're not designed for this kind of interaction).
-- Pavel
There are several ways to solve this.
The first that comes to mind is to change the page to AJAX. AJAX would not force a page jump forward, hence there will be nowhere to go back to.
The second way is to have a check on the previouis page, for example set "Session("if_search_go_here") = Request.Url.PathAndQuery" and unset it at the right place. If this is set then the search page will just forward you to the detils page again.
probably more. :)
I want to transfer one asp.net page form values to another page when i click to submit button. But you know, every asp.net page postbacks to itself. Do you know any way to do this?
Take a look at: Cross page posting
Retrieve the values from the request object or if required store the form values in session.