Check weather the page is out of focus asp.net - c#

I am trying to build a online exam project. Once the student login the exam page will be in fullscreen mode. I want to know if the student presses any shortcut keys like Alt+Ctr+Del or Alt+D etc. which ever it may be. I just want to know is it possible to find out if the current page is out of focus ? So that I can end the session at that time.
Please help me with this.

if(string.Compare(Request.Url.LocalPath,"MyPage.aspx")==0)
// maek your session Null whatever you want
}
This can be done in master page easily

Related

Possibility to return to ScanPage

In Xamarin app, I have a page after scan a QR Code. An AlertPage to show if the ticket is good or not (I don't want a DisplayAlert). On this page I want a button to return to the page before the scanner, and an other button to return to scanner.
If you want I have 3 pages:
ListPeoplePage (with a button to go to scan who create new ZXingScannerPage);
ScannerPage (when you scan you go to AlertPage);
AlertScanPage (with backbutton to go to Scanner and an other to go to ListPeoplePage).
I'm not sure if it's possible and I have problems with my NavigationStack (I have never the good number of pages).
If you know a good method to add this AlertScanPage it would help me.
My question is to go from AlertScanPage to ScannerPage.

How to disabled button after user have clicked the button before in asp.net using C#

I am currently creating a seat reservation system. In my system, if user select Seat 1 and proceed till the end, when the system come back again (I have a button linked to first page from the last page), the Seat 1 should be disabled and cannot be chose already. But somehow my code still allows it to choose. Why is that?
I am using this code:
if (seat1 == "Reserved")
{
ImageButton1.ImageUrl = "seatreserved.png";
ImageButton1.Enabled = false;
}
The image does change so I know the value "Reserved" had successfully passed to this page. But somehow the ImageButton1.Enabled = false; did not work.
Please help, thank you.
You are not saving the state of your actions anywhere at least you don't explain it. When you reserve a seat in your app save the value of the seat in some source-> db xml or whatever you like. After that on the next opening of your app load the reserved seats from this source and make disable this buttons.
If you use DB and you have two tables Event and Reserving seats. When you click on the button you are inserting data in Reserving with EventID='The ID of Event' and SeatNumber the number of the seat.
After that when you go into this event again load the data from Reserving table for this Event and disable what is needed.
try to clean project and rebuild again.. if problem still occurs then try to add new control and implement code again. Sometimes these kind of things happen in .Net Framework.

Page locking in ASP.NET

Here is an overview of my ASP.NET Page setup. Framework is 4.0.
There is a Page with tabs with a user control in each tab of it. There's a lock button on the Page which locks and unlocks the page. The page will be auto locked when any user opens it. This is the current setup. But now we need the following scenario:
The Page should not be locked on user opening it. But when he tries to edit or change any info in the fields of the Page it should lock the Page. I guess this is more of a client side Issue. So, when another user tries to open the Page and edits it, it will be locked for him too as it is a separate client. So, there should be a mechanism in ASP.NET to notify the server that a page is locked when user tries to edit the info on the Page so when other users try to modify the page, they get a 'locking' error.
So my question is how do I achieve the above and what are the things to consider?
I know in ASP.NET we can write code for user events like clicking a button etc.. but not sure of techniques for achieving the above. Any input would be a great help.
You could store something in the application cache with an expiry period set to however long you want the page 'locked' for. Each time there is a postback you would check for this value in the cache and either 'lock' the page or return an error to the user. Each time the page is loaded when not postback you would disable the button and/or input controls.
Something like this in Page_Load should be a reasonable starting point:
string usernameWhoHasLock = (string)Cache["PageIsLockedByUser"];
if (usernameWhoHasLock == null)
{
// Page is not locked, lock it:
usernameWhoHasLock = HttpContext.Current.Identity.Name;
Cache.Insert("PageIsLockedByUser", isLocked, null, EXPIRYDETAILS);
}
else
{
// Page is locked. If IsPostback, allow edits if is the user with the lock, otherwise return an error. If not postback, disable the edit button unless is the user with the lock.
}
For the arguments to supply to Cache.Insert decide what expiry policy you need and refer to the documentation here. IsPostback documented here.
you may consider implementing pessimistic locking in database where record will be explicitly locked and stay locked unless it's released (in this case saved/cancelled). not very easy to implement properly though.

Come back from third window to first window in history

I'm developing a Windows Phone application and I have three screens:
Main screen
Login selection screen.
Sign in screen.
When user has signed in and push "sign in" button I want to come back from screen 3 to screen 1.
Now I come back to screen 2 and immediately to first one. I don't want to show 2 screen.
Is it possible to do this?
Try this
Assume your pages are named as FirstPage.xaml, SecondPage.xaml, ThirdPage.xaml
//Check for the first page and remove the remaining back stack in your ThirdPage.xaml
while(!NavigationService.BackStack.First().Source.OriginalString.Contains("FirstPage"))
{
NavigationService.RemoveBackEntry();
}
NavigationService.GoBack();
Somewhere in page 3 add
NavigationService.RemoveBackEntry();
This will remove page 2 from the back stack. Now when the user hits the back key, he'll navigate directly backwards to page 1.
But as Amal Dev noted, Microsoft wants you to let the user navigate to the previous page. This rule doesn't seem to be enforced too much, it's probably meant as "never ever confuse the user". If you confuse the certificating tester, your app will fail certification.
You can use the NavigationService.Navigate method for this.
NavigationService.Navigate(new Uri( string.Format("/your page name.xaml?val={0}", ValueTextBox.Text), UriKind.Relative));
Please refer the link given below.
Simple Navigation In Windows Phone 7

Getting url of a page once making a form submission

I am designing a winforms based testing app (which is based upon WatiN). I specify a page to test and the value to insert into a textbox, and then click the corresponding button.
Is it possible to add a query string to the request I make (when clicking button) and then get the URL of the next page? Based on this, I need to screen scrape it.
Not sure about Watin syntax, but in Watir (Ruby version) you can get URL of the page displayed in browser with
browser.url
Or do you need to get URL of the next page before you open it?
Based on your comment to AmitK, Ċ½eljko's answer is right.
In WatiN (and C#), the syntax is:
Console.WriteLine("The current page is:" + ie.Url.ToString());
(just in case: 'ie' is the browser reference, use whatever object you use to enter text and click buttons)
What exactly do you mean by "next page" ? Does the form when submitted redirect to another page? If so, you will receive a HTTP 302/303 status code with the URL of the next page.

Categories