I am developing a page tracker app where i need the login time,log out time ,session id,logged in user and each page accessed by user,time spent on that page and the list of event's in a page that are fired when controls are clicked,checked or selected.i dont want to use google analytics
For now i am accessing all the details by writing session start etc in http modules and everything is achieved.i am storing all the data in a hashtable and throwing them into db when logout is clicked or session time's out.i am struck on how to identify if logout button is pressed .
i can directely write the piece of code for inserting the statistics on the click of logout button itself but i dont want to do so as i want to capture the logout button id or text in http modules and then write the logic in http module.i tried to capture the sender but it's throwing an error by referring the asax reference instead of button reference
how can i acheieve this(track which button is clicked on a page and get the id in http module because the http module triggers for every postback or load)?
You could use your HttpContext.Request.Form object. It contains Key "__EVENTTARGET", which value equals to ID of object that sends POST to Server.
Related
I am trying to implement a like counter. That on a click of button increases like count by one in the database and then I am changing its text to "unlike" after clicking again my value is decrementing by 1 in the database too. It all works fine untill the page is posted back.
For eg. If a user clicks like button then text of that button changes to unlike. But if the user reloads the page then. He again gets the button as "like" but not "unlike" is there anyway I can save the state even after postback in asp.net.
Thanks in advance.
You will need to store the 'like' state in a session variable if you want it available between page switches/reloads.
This might help:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e43755ba-49f1-49b9-aa68-448ecf033a62/how-do-you-store-session-variable-in-c?forum=csharpgeneral
Alternatively, get the 'like' state from the database when generating the page.
If you're still experiencing issues, your browser might be caching the page.
If you are on to Javascript, you can try SessionStorage to hold values between page refreshes. It lasts only within the lifetime of a browsers tab and automatically destroyed when the tab/ browser is closed. Values remain completely on the client side and managed by the browser.
Session Storage (W3Schools)
Ex (extracted from the above website):
// Store
sessionStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = sessionStorage.getItem("lastname");
Silly question,
Is there a way to redirect an application back to it's self from a button or a hyperlink (without a simple postback), as if you were typing the application's url in the address bar for the first time?
The reason I ask is because I have an application with a parent web form and then Telerik RadMultiPage that renders each page (or web user control) one at a time. I do not have the option to use the "RenderSelectedPageOnly" property in this case because I want the user to be able to navigate between pages with the TabStrip.
On the very last page, I want the user to be able to start the application all over, as if visiting the URL for the first time. The application is session based and when landing on the last page, I clear all session variables (Personal Information). On the last child page, I have put a button with Response.Redirect("default.aspx", true); event. The problem is that previous pages contain if statements that basically listen for certain session variables and act accordingly.
When I run the Response.Redirect("default.aspx", true); on the last PageView, I get "object reference not set to an instance of an object". I know it's because of Session variables that no longer exists but this happens because all MultiPage views are still loaded on a postback.
Any way to just simulate typing a url in the address bar and hitting submit?
You can accomplish this very easily with javascript.
Javascript
function ReloadMe() { window.location = window.location.href; }
HTML
<input type="button" value="Reload Me" onclick="ReloadMe()" />
I have registration form, suppose there are 5 fields, and all are required i.e. mandatory.
My problem is that when user login & fill 2 fields of that registration form & click browser back button, then I want to restrict user to same form & Show requiredField Validator messages of incomplete fields. So How can I fire Validation on browser back button & restrict user on same form.
You cannot affect browser behavior when the user clicks the Back button.
The correct solution is to check right after user have been login, if he has complete the registration entries on database, and if not you redirect him to fill that data.
From your comments, to alert them a solution is to capture the onbeforeunload and check there if they have fill out everything or not, show your message.
Simple example, you just need here to place your conditions.
window.onbeforeunload = function() {
return 'You have unsaved changes!';
}
You can't disable the back button (see the other answers and their comments).
What you can do is check on every page whether the user is logged in. If not, redirect him to your login page. This way the user can't access the site without logging in, which I guess is what your client is really after.
I have a button in my aspx page, which in code behind the value of postbackurl gets set. I updated the code to add click event handler and added Response.Redirect code to redirect user to the page once the button is clicked. The only reason i ended up adding click event was because i had to add some extra logic when the button was clicked including redirecting to same url, that was used in postbackurl. The page does get redirected on click however it seems like all the hidden fields from the field gets lost once the form get redirected to the url.
Is there anyway i can submit the form without loosing the hidden data.?
Maybe one way you can solve this problem is to use the server side Transfer() call.
http://msdn.microsoft.com/en-us/library/540y83hx(v=vs.85).aspx
In most cases I've seen what you really want to do is pass the information for the new page using URL parameters. Take all the stuff the new page needs and put it into the url (encrypt if it is security sensitive).
If the only issue you are having is when you want to stay on the same page, this is simple, just have the click event handler return without doing a response.redirect or a transfer.
Post the code if this is not working for you.
I'm trying to solve a problem where I'm intercepting a request in Navigating and want to inject an additional request parameter into that request before passing it off.
Here are the steps:
First I make a request via WebBrowser.Navigate(). I have an event handler to capture the Navigating event.
The request hits the Navigating event (before the actual request is made). I, at this point, want to either cancel the request and issue a new request with the added parameters, or somehow alter the current request to have the correct parameter.
Unfortunately I cannot simply call the Cancel event, and re-issue a Navigate call because of one problem. This request is from an iframe, so its one level deep, and the navigate call would clobber the end result of the document contents (as it would show only the iframe contents and not its parent's).
Any suggestions?
It seems impossible to inject a new parameter into a request on low level.
A recommended way is to alter html source of a page sends a request. For instance, add a hidden input field inside a form just after page is loaded. IMHO.