Can you "remember" what link is clicked on a webpage? - c#

I'm working in Visual Studios to create a website for a movie theater (for class) I'm wondering if there's a way to "remember" what link is clicked for a show time? I know I could just create a webpage for each time, but I'd rather track an id, if that's possible!
By clicking the link, they'll go to the right page, but is there any way for me to put into the system what time they clicked? I couldn't find any similar questions here.

you could use sessions to hold the showtime selected. create an LinkButton with an onCommand that creates a session before redirecting them to the seating chart or checkout page.
so say a user is on your movie page and the user selects the 12pm showtime. When the user clicks on the link, it will run what ever is in your code behind. You can create a Session["DateTime"] and set it to the value of the linkbutton. then, redirect to the seating page.
on the seating page, you can check if there's a session. if it finds one, then you can load the seating chart or purchasing page. if it does not find one, you might want to redirect them back to select a time.
HTML example:
<h2>Next Big Movie</h2>
<asp:LinkButton id="lbNBM12pm" runat="server" OnCommand="lb_Click" text="12:00pm"></asp:LinkButton>
Code Behind example:
protected void lb_Click(object sender, EventArgs e)
{
string time = (sender as LinkButton).Text;
Session["TimeSelected"] = time;
Response.Redirect("/nextstep.aspx");
}
and on the next page, you'll read what was passed over in the page load and set the Selected Movie time text:
protected void Page_Load(object sender, EventArgs e)
{
if(Session["TimeSelected"] != null)
{
MovieTime.Text = Session["TimeSelected"].ToString();
}
else
{
//user did not select a time
//possibly redirect them back to the showtimes page.
response.redirect("/previousepage.aspx");
}
}

If I understand it correctly. First, create a table with the following columns:
create table Links
(
id int identity,
link varchar(100),
timeclicked datetime
)
then fire an ajax or a simple HTML POST request to submit what link is clicked in a spefic time.

Related

How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.NET classic Web-forms with c#?

I'm doing a project for school and i have this page with some search results.
When i go back to the search results page, the browser asks to "Confirm Form Re-submission" and i would like to avoid this.
I haven't done nothing so far to solve this issue besides searching the web for a solution and not had not found one.
Browser message:
Confirm Form Re-submission
This web page requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed.
Press the reload button to resubmit the data needed to load the page.
ERR_CACHE_MISS
The problem lies in that you are doing a post request, and if the person making use of your web page refreshes it, it does what it is supposed to do resubmit the post request.
Hence, there is no way of preventing this issue from happening, what you could rather do is changing the way you obtain the values from a post request to get request.
Hi. Found the solution for my problem.
So what i did was, stored the value in session, redirect to a loop page and back, and just preform the search on form load. Now i can go back and forth with no problem. Here is the code i used:
Search page:
protected void btnSearch_Click(object sender, EventArgs e)
{
Session["searchValue"] = txtSearchValue.Text;
Response.Redirect("loopPage.aspx");
}
Code on LoopPage.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("searchPage.aspx");
}
search page again:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["searchValue"] != null)
{
...preform search and create objects to present results...
}
}

Losing values after refreshing button asp.net

I have the following project :
It's a page that on Page_Load it fills a TextBox named Email and a TextBox named UserName with a value obtained from asking a database.
Then there is this button, if the email is not null(user is not registered) it will let you register, otherwise it will let you change the email linked to your username.
The thing is, when trying to modify the email, doing an update query, the page preloads, taking the new value placed on Textbox Email the same that is retrieved from the database, making so it will never change.
I've tried to see if it executes the query and it does.
I've tried everything, keeping the variable on a hidden label, creating two different buttons with no luck as when it reloads the code those values are empty again.
I was thinking if I could keep the variable somehow that isn't cookies.
I think You know What is happening.. On every Post back the Page_Load event resetting your Textbox Value
Use IsPostBack to bind the value only on 1st load of page
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//bind dropdown and fill textbox here
TxtName.Text = "Your values";
GetDropdowns();
}
}
I hope this will solve your issue
I totally agree with Kanis XXX, you can use IsPostBack to fill the values only at the start page, and not on other postbacks. In my experience, there are some other advices for your problems:
Using Viewstate, Session state,... to keep your working variable. You can have more detail here: https://kimphuc.wordpress.com/2009/10/18/the-difference-between-viewstate-sessionstate-cookies-and-cache-in-asp-net/
Try to use UpdatePanel, this could be useful in some cases, let you refresh or update data just a part of your page, not the whole page. https://msdn.microsoft.com/en-gb/library/bb398864%28v=vs.100%29.aspx

Windows Phone back button

I need to go back to a particular page when I click on a button. more like custom back button.
I can go exact page, if I know what is the page is,
private void button_click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(Page1));
}
Also I can go back to the previous page by
if(this.Frame.CanGoBack)
{
Frame.GoBack();
}
But how can I jump to the page before the previous page at once?
Any record of page history?
You can use NavigationServices.BackStack to access on an history of your previous pages.
But you have not specific method to go back from 2 pages at once. However, if you would jump to the page before the previous page you have just to called NavigationServices.GoBack() two times.
Moreover, if you would go back to a specific page, you can know its index between backstack and make a loop with the GoBack method.
You can get all pages from BackStack as a List :
var lstAllStackPages = this.Frame.BackStack.ToList();
and make a for loop to get your specific page and navigate to it.
Thank you #CoderDennis, I figured it out. hope it will help to someone else.
I wanted to move back to the Main page if I have come along the Main page,
foreach (PageStackEntry stack in Frame.BackStack)
{
//check if stack contains history of the main page. (Solution name: Helloworld)
if (stack.SourcePageType == typeof(HelloWorld.MainPage))
{
Frame.Navigate(stack.SourcePageType);
break;
}
}

Redirecting to a particular page/session with updated data in asp.net using session or some other way

I have a page where the data is by default loaded with the daterange of Sysdate to SYSDATE+18. The date can be selected over a dropdown. Which ever date user selects it shows the data's in date range of that selected date to selected date+18 days.
So based the Data in page is changing. But the page by default loads with SYSDATE.And each row has amend/Delete functionality. Now if a user click on Amend/Delete then user will be redirected to Amend that partcular record in a screen. In that screen there is a back button
The back button click event has been written like that
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Rota.aspx");
}
So it is redirecting the Main Page with data loaded as per Sysdate. How could I display that particular date's data Which I amended in Amend screen - Also it would be showing the updated data.? Probably use of session would help..any suggesion guys how could I proceed with the code?
You could try one of the options here: http://msdn.microsoft.com/en-us/library/6c3yckfw(v=vs.90).aspx
I managed to use the Previous.Page property to get something similar for me.
Can be Done via
Session["Date"] = DateTime.Now;
Read from session
var date = (DateTime)Session["Date"] ;
OR
You can set the postbackurl property of the button to the page you want to redirect.
Then on that page you can use
<%# PreviousPageType VirtualPath="~/SourcePage.aspx" %>
once this is done
if(PreviousPage != null)
{
var name = PreviousPage.propertyname;
//OR
var control = PreviousPage.Controls[0].FindControl("controlname");
}

Restrict a page navigation to one control

I am making an online exam website where a user is taken to a page where there are multiple choice questions. I want to set it up so that once a user navigates to this exam page, he cannot navigate back. The only way he can get out of it is by clicking the submit button and then he cannot access that page again. The questions on the exam page are in an SQL database. I have everything done, the only thing I need help with is restricting the navigation of the page.
It can be done by using Session varaible.If u have 3 pages say a.aspx,b.aspx,c.aspx then create 3 session variables such as
Session["a"]="some value";Session["b"]="some value";Session["c"]="some value";
On the pageload of the a.aspx check if the session contains value or null.If it is null then u can make sure that it is the first time that page is loaded else do what you want to do if user tries to visit a page which is already viewed.
Please try this code
//Code for page a[a.aspx]
protected void Page_Load(object sender, EventArgs e)
{
if(Session["a"]==null)
{
Session["a"]="Some Value";
}
else
{
// do code if user visit the page again.
}
}
Similarly you needs to do for all the pages.
I hope this will solve your problem.
You could use cookies or session to keep a tab on the pages the user has gone through so you can prevent them from going back.

Categories

Resources