loading the same page with and without session variables - asp.net

I have an aspx page. This page is used for both create and edit.
While editing, I set a session variable and load the same page.
While creating , user has to click on menu option and it get redirected to "CreatePage.aspx".
While editing, it will be redirected on click of a column in a grid . this time the response.redirect happens to the same page with Session["Id"] set to some value. Now my question is how and when do I set the session to null?
This should work for Create and Edit using the same page. Any help will be greatly appreciated.

The how is easy:
Session["Id"] = null.
About the when: Can the user cancel a edit/creation? If so, what happens then?
The change of the session variable should be done when the user clicks on either the menu option or the grid column AND when the operation has finished (by either an OK or a Cancel).
Anyways, Changing data in a grid can easily be done with the GridView control. You can see an example here. So you might be trying to "reinvent the wheel" here...

Related

Refresh content page when master page is updated

My site uses a Calendar control to determine what date to get data for.
Because this calendar should be visible on every page, I've placed it on my MasterPage.
If the date on the calendar is changed, it should cause the data shown in the Content page to be updated with data specific for the new date. Essentially, it should cause the page to be reloaded.
Because the calendar is on the MasterPage, that's where I'm putting the SelectionChanged event handler, but I'm not sure how to "reload" the content page from here. All I can think of is a Response.Redirect, and I'm not sure if that's the best option.
Can anyone give me any suggestions?
Decided I'd simplify this and make the master page element a hyperlink that redirected to a page that had the calender on it and "Save" button on it.
I found this much easier to manage...
The calendar loads with today's date, allows the user to select another date and the save button writes the new selected date into a session variable read for the data that is to appear on all the content pages.
It means the user has to specially go away from what he/she is currently doing in order to set the date, but I actually prefer it this way.

ASP.net Using a Session Varriable to move a GridView SelectedDataKey to another page

Help please!
I am pulling out what little hair I have left over this and can't find an answer.
I am attempting to move the selected row in a grid view to another page and use the SelectedDataKey or the primary key value of the selected row to indicate what data should be displayed in a grid view on another page. This is the last little bit of a school project that I can't figure out.
What I am doing on the first page is to use a button click event to set a session variable that looks something like this. Session["Select"] = GridView1.SelectedDataKey; The button will then send the user to the next page. Response.Redirect("CustomerAccounts.aspx");
Once on the next page I want to use the primary key selected on the first page to show only the data with a coresponding value on the second page by using a where statement in the next gridview. So I am setting the [CustomerID]=? Session("Session["Select"])
Am I setting up the where correctly in the second gridview?
I like setting up such things with querystrings.
I made a video tutorial on youtube doing just that a while back
http://www.youtube.com/watch?v=HRjZ_0JpO2M&list=UUgtKyNvllU9E6c2Mi8OtzCQ&index=5&feature=plcp
I also made a tutorial showing how to load the detail gridview nested in the master gridview with jquery
http://www.youtube.com/watch?v=nJp14o_1wZQ&list=UUgtKyNvllU9E6c2Mi8OtzCQ&index=4&feature=plcp

Automatic page refresh even we navigate to another page

i have a problem in page navigating. please help me to solve out.
in one asp.net page forexample Page1.aspx i have dropdown when we select an item in dropdown that would display in a label. Then we navigate to another page from page1.aspx to page2.aspx by clicking linkbutton in page1.aspx. Again if i come to page1.aspx that previously selected value of dropdown should appear in label.
please help me.
HTTP is a stateless protocol. This means that it'll forget anything that you don't tell it to specifically ask it to.
When going back to Page1.aspx, your program has no idea what was selected before.
In terms of persisting user choices, you should look into storing them in Session ( or alternatively, cookies ) and checking for a pre-existing choice when returning to Page1.aspx.
If you have a saved value for the user at that point, you'll be able to set the correct value during the Page_Load event.
If it is like a wizard, I suggest you use a wizard control in the same page.
here is an example,
https://web.archive.org/web/20211020103244/https://www.4guysfromrolla.com/articles/061406-1.aspx

How can I maintain gridview page index while navigation from the form?

How can I maintain gridview page index while navigating away from the form and getting back by either the browser's back button or custom navigation button?
Save the current index in Session or other kind of state source (db, or file system), which crosses the bounds of single form (not a ViewState for sure).
I guess Session is the best for you.

Alert on moving to a different page of a grid when user changes contents of textboxes in a Grid

In a ASP.NET application I have a paging RadGrid which shows up textbox in each row. Outside the grid, there is an OK button to save the content of all the textbox. If user changes text in any one or more of the textbox and without clicking on the "OK" button, tries to move to a different page number (of the grid by clicking on the page number), he should be prompted for confirmation of save or cancel the changes.
I am guessing that one can write a Javascript function which would look for any form input control (textbox in my case) and detect changes and If there are changes, would prompt the user. However, I am not sure where I can call this function from? Any suggestion on this or a better way to achieve this would be appreciated.
I am using RadGrid but I guess this should be applicable to GridView as well.
I am not sure if this will help exactly but it might at least give you an idea:http://www.codeproject.com/KB/ajax/ajaxdirtypanelextender.aspx

Resources