I am using two tabs in my page like the attached image.
.
Here, after selecting the value in all dropdownlist controls then, i click the generate button. so, the tab is moved from parameter to report. Then again i click the parameter tab. At this time all my dropdown controls shows null value.
but I want all the dropdown values which i selected before.
how can i get the dropdown control values?
It's important to remember that web pages like this are stateless. One request won't remember anything about another request.
So in your situation, you're putting in data, then it sounds like you're clicking a link (or button) that redirects you to another page, then you try and go back to the first one, and it has to fire off yet another request, with no knowledge of the first one's state.
Given that, it seems like you have two primary options (and dozens of others that I won't bother mentioning):
Move the tabs to be on the same page. (My recommendation)
There are lots of controls out there, or you could easily write one yourself, that don't separate tab pages via multiple requests. If you did that, switching tabs wouldn't lose the data.
Add a "save" button, and disable the other tab.
This way, the user actively has to save the data before being able to leave the page via another tab. The biggest issue here comes in the form of usability.
Which one of those you choose is dependent on a number of factors, not the least of which being code maintainability and the size of requests.
Related
I simply need to copy the textbox input data to another page. i have a datagridview from Home.aspx when i select data from it. it will display the row data to the textbox. now i want to copy/pass the data to another page. how can i do that? i tried following codes but it does not work.
This is the 2ndPage Code on load_page
If Not Page.PreviousPage Is Nothing Then
Dim SourceTextBox As TextBox
SourceTextBox = CType(PreviousPage.FindControl("TextBox1"), _
TextBox)
If Not SourceTextBox Is Nothing Then
Label1.Text = SourceTextBox.Text
End If
End If
Ok, a truckload of issues here.
First up:
page.previouspage is ONLY available if you used
Server.Transfer("~/MyCoolWebPage.aspx")
And as general rule you don't a "server side" transfer/jump/hop to a page this way. Trying to keep this post short, but a server.Transfer() means that no real browser side jump to the page occurs - only a server side transfer. That means that the previous URL does not even change! And thus as a general rule, a jump to a page occures from a button click on a page, and that button click can be a client side (JavaScript) click, or a standard button click that executes the Response.Redirect(). However, in both cases, it really is a client side browser request. You as a general rule thus don't want to build or write a web page that "assumes" that a Server.Transfer() was how you landed on that page.
Because of the above? Well me.Page.PreviousPage is ONLY available if the page you are landing on was the RESULT of a 100% server side re-direction to a new page. And that simply not going to be the case, and thus for the vast majority of your web pages, then page.Previouspage will be null, and of ZERO use to you. (it's simply not available).
So, now we back to traditional means and approaches to "transfer" data to the next page.
Remember, that page is state-less. That means EVEN on the same page, all values, and variables are lost between each page load. Even a simple button click means the page will re-load, but that re-load will see all your values lost. Now most controls such as a text box, or even the gridview can and will keep what is called their state for those "round trips" when you click say on a button.
Now, in your case, no doubt you are clicking on a button, and jumping/loading to a new web page. Thus, all previous controls, data and everything you had in existance on that previous page is all gone, and lost.
So, how to pass values give this "state-less' nature of web pages?
Well, a very common way is to use parameters in the URL. However, I find them quite ugly, and users can also mess with those values. However, for really large web sites, we see the parmaters in the URL often used, and that's because the web site does not want to spent the energy, the time and even the memory and resources to keep track of say 1 million users hitting that web site.
But, there is another very common means to "save" values in what we call a round trip. That handy dandy "temp" storage system is called Session(). Now Session() should be treated as a precious and limited resource, but it is quite much how you can (and should) pass values around. The beauty of these values is they "persist" and keep their values between post-backs. And this includes jumping to another page.
So, to pass that data to the next page?
Simply stuff that data row into the session, and then in the target page, you can then get/grab/use/pull any values from that one row of data.
So right before your response.Redirect("to my 2nd page page"), you can do this:
Session("MyTextBox") = me.TextBox1.Text
Now above is fine for one text box value. But, you want to pass the whole row.
So, you can go:
Session("MyListDataRow") = MyRowOfData
Now, you don't explain how or when or where you selected the one row of data. But you can certainly shove the one row of data into session, and then show/display it on the next page.
One more SUPER DUPER WHOPPER:
If you do pull out the selected row into a datarow (as opposed to datatable, or dataset), then keep in mind that .net serializers don't support the datarow (why, I have no idea!!!). So if you using "in-memory" sessions(), then you are ok. But if you ever decide to adopt SQL based session() management, then that code will start to fail. So, either shove in a ListViewDataItem, or a datatable to pass that row of data, and not a datarow.
I would thus just not pass a "datarow" in Session() and avoid the above horrifying revelation that .net left out that data rows don't support serialization! (holy moly!!!!).
So unless you are using a server.transfer() for this, then page.previous is not valid nor available. And if you using a master page, then you have to first dig and get the master page refernce, and then the ContentPlaceHolder if you ARE using a server transfer and you thus do have use of page.PagePrevious.
Edit:
Having said all of the above? Well, if you have a click event on a listview (or datagrid) row, then a server.transfer actually is "one" of those good use cases in which you may VERY well consider a server.transfer(), since the you have full use of the listview/datagrid data in that 2nd page though use of page.PreviousPage. Just be aware that you have to pull down one more level to get at the content if you using master pages.
I am completely new to web development. The question I have is rather simple (I guess), but after multiple hours of using google and experimenting I am still without any solution. The problem I have is probably not how to do it, but which keywords to use while searching.
I want to create a simple website. (For testing I use Caddy Server). For my website I use a simple index.html file. On my website I want to have 9 buttons, which will be disabled once clicked. After refreshing the page, every client should also see the changes, so the button-state has to be stored somewhere on the server.
Then there will be another button, which sets the web page to its initial state (all buttons enabled). The purpose of this web page is that 2 persons can click buttons successivley until only one button is left enabled (the web page reloads itself every second on every client). This will be used to select a certain map from a map-pool of 9 maps.
My main problem is, to store the button states, so after refreshing the page the buttons should be still disabled if they were clicked. All clients should see the buttons as diabled once they refresh their pages. Do I have to implement a database for this or store the button states in xml or json? Do I need javascript, jquery, php or ajax for this? I do not want to make it very complicated, so if I need for example a database for this, I will probably just give up.
What I'm asking for: Any point in the right direction on how to implement a simple button that keeps its state after reloading the page would be much appreciated. I found a solution for this using JQuery, but it does not work for me (button does not preserve state after refreshing See here).
Thank you so much for any help!
Your server will need a data store (database) to save the values desired for each button.
Client Side
Set disabled attribute on all relevant buttons in your HTML. On (client-side) page load, fetch the value(s) from your server (database) and depending on what the returned value(s) are, .clearAttribute("disabled") on all buttons accordingly.
Server Side
Have your server set the disabled attribute on the HTML <button> elements based on values in your database prior to serving the HTML to your client(s).
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 an asp.net application with a search page, with criteria and result display on the same page. I want to keep a copy of the populated search page to redistribute it later to the same user, upon the button click on another page. It's kind of a "return to search" button. How can I do that?
Here is some context:
The search criteria is made up of some basic controls, and the results are then (after postback) displayed in a GridView. I also have a master page. Simple as that.
Now consider the following scenario: The user can investigate the results by clicking links that show detail pages, and can drill down over quite many detail pages with associated data. If he/she wants to get back to the search results he/she needs to click the back button of the browser quite many times.
I would like to provide a "Back to search" button on the master page that allows to return to the populated search page with one click.
Note:
I can not use the browser history in any way because it must work also when the user opened one of the detail views in another tab.
I have seen Keeping the Viewstate persistent and retrieve it on demand but it hope there is an easier solution because my grid is paginated and I have also more than one search page, where I would like to return to just the last one used.
Thanks, Marcel
I can offer some logical ways to resolve this problem, without using specialized asp.net features if they exist:
1) Is there some way to save the search string in GET request? So you can save it some way between moving through pages?
2) Another way is caching search pattern (with all filters or what you need there) somewhere - in database, for example and contain some key in get request, which would point on this pattern.
Is their a case for using input buttons as page links, when your linking to the next of a series of pages of a form where your filling out information?
UPDATE - Ive inherited a site. One section is a series of pages of forms that users fill in. The 'next' link to the next page is currently an input button, not a normal link.
Is this bad from a standards / semantics point of view?
I am not sure what you exactly want. But what about, you can use the button to navigate through the pages. Just put the url address of the next page.
<form action="page_number_2.htm">
But you will need to store formulat data from every page. I mean, if the user fill the formular on one page and go to the next formular, you don't want to lose the data from the filled formular. You can stored them with php until the user will reach the final formular step, where he will klick submit-button.
Actually the link is used for navigation through the pages. But in this case, if I understand right, you need to send data from formular, if the user go to the next formular. So in this case, better to use button. Still you can make this button look like link.
It is possible to make links appear as buttons. However, in the situation you describe, it would be a bad idea. The form data will only be submitted to your server if you use a form. Allowing the user to click a link to go to the next page will cause you to lose all of the data they entered (Unless you are collecting that data via AJAX).
It is usually best to allow page element to perform the functions they were designed for to avoid confusing your users. Users expects links to work like links, and buttons to work like buttons.