I am using 'iFrame' on the website, and right now, whenever I directed to the another page (says Register Page) and I click F5 (Refresh button on the browser), it will go to the Default.aspx and not Register Page. I notice that while I directed to the Register Page or another Page, the url stays on: www.something.com/Default.aspx, but it should be www.something.com/Register.aspx. I think the cause for it cannot go back to the current page is because of the URL linked to the Default.aspx.
ID for Main Frame is MainFrame and here is the code:
if (Session["AFFM_RoleCode"] != null && Session["AFFM_RoleCode"].ToString() == "0")
{
// If the user is not logged in
if (Session["IsAgent"] != null && Session["IsAgent"].ToString() == "1")
{
mainFrame.Attributes["src"] = "BlankPage.aspx";
}
else
{
mainFrame.Attributes["src"] = "Main.aspx";
}
}
How do I can solve this problem?
Your answer much appreciated!
Thanks
This is a quick patch you can do to this, add a session to your register page when it load, such as
session["Load"] = "register";
and when the page is refreshed, if you find register in the load session, redirect it to the register
if (session["load"] == "register"){
session["load"] = "";
//you redirect code
}
Related
I am working with an ASP.NET site with a C# back end. There is a .Master page where the tag is, and other search pages on the site will search when you hit enter after filling out the form. However we have one page that has a few text boxes and when you hit enter to search, it appears to just refresh and reload the page without searching. In order to search you have to hit the search button (which is an igtxt:WebImageButton ). All of the solutions I have found to this issue so far involve people using javascript to call some kind of function on submit. As far as I know there is no javascript being called when you hit the search button, it is all in the C# code. Once again I find myself searching SO and other sites for an answer but none of the solutions seem to fit my situation. The form tag is as follows:
<form id="form1" runat="server">
The web image buttons call a btn_SearchClick function that runs the search code. But since the form is started in the .Master file I can't edit that as it would effect all other pages as well. Is there any way to have enter call the btn_SearchClick from the form without having to put it in the form tag? I'm not sure what would've changed to cause this behavior on one page and none of the others.
if (!IsPostBack)
{
TextBox1.Attributes.Add("onKeyPress",
"doClick('" + btnSearch.ClientID + "',event)");
}
<SCRIPT type=text/javascript>
function doClick(buttonName,e)
{
//the purpose of this function is to allow the enter key to
//point to the correct button to click.
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
if (key == 13)
{
//Get the button the user wants to have clicked
var btn = document.getElementById(buttonName);
if (btn != null)
{ //If we find the button click it
btn.click();
event.keyCode = 0
}
}
}
</SCRIPT>
or u can use default button.it's work while cursor's in this box
protected void Page_Load(object sender, EventArgs e)
{
this.Form.DefaultButton = this.btnSubmit.UniqueID;
}
Add some jquery to control the Enter key behavior on your textbox. Something like this:
$(function() {
$('#<%=txtTextbox.ClientID%>').keypress(function (e) {
if (e.which == 13) {
e.preventDefault();
$('#<%=btn_SearchClick.ClientID%>').click();
}
});
});
I've read a few articles regarding getting values back from a modal popup in an ASP .NET page, but they all seem to use JavaScript to accomplish this which isn't really want I want to do if possible.
I have a web user control which has a repeater that I populate from a list into a table. Each row has a link button which has a redirect url with a value as a query string.
Then I have another web user control which is just a link button with a panel and the repeater web user control that once clicked shows the actual modal popup.
Is it possible to get a value from the web user control once the link button on the repeater is clicked without having to redirect to the same page? I basically want to click on the link, show the modal and once closed, want to access the value.
I'm populating the repeater with the links as follows:
string linkUrl = "";
string action = "";
if (Request.QueryString["action"] != null)
{
action = Request.QueryString["action"];
switch (action)
{
case "SetupCompany":
{
linkUrl = "<a href=CreateCompanies.aspx?companyId=";
break;
}
case "ViewCompany":
{
linkUrl = "<a href=ViewCompany.aspx?companyId=";
break;
}
}
}
CompaniesBusinessManager mgr = new CompaniesBusinessManager();
var companies = mgr.GetCompanies(txtCompanyName.Text, txtRegistrationNumber.Text);
if (linkUrl != "")
{
foreach (var c in companies)
{
c.Name = linkUrl + c.Id.ToString() + "&action=" + action + ">" + c.Name + "</a>";
}
}
rptrCompanies.DataSource = companies;
rptrCompanies.DataBind();
if you don't want the page to be redirected, you will need to use javascript.
There is now way you can pass values from different controls without going back to the server.
In case you keep it without the javascript:
I think you need to pass values from one user control to another. I used to accomplish this by firing reachable events between them.
For example:
in your parent view:
<uc:YourUserControl runat="server" ID="UserControl_Test"
OnYourCustomAction="UserControl_YourUserControl_YourCustomAction" />
In your user control:
public event EventHandler<CustomActionEventArgs> YourCustomAction;
also in the same user control create a public trigger method to be access from others usercontrols
public void TriggerCustomActoinEvent(CustomActionEventArgs EventArgs)
{
if (this.YourCustomAction!= null)
{
this.YourCustomAction(this, EventArgs);
}
}
Hope this help, in on my way to home this was from my mind!
Without a page postback or JavaScript it not really possible. If you are using modal popups you are already using JS, so why not just get the value in JS? You could setup an event handler for all repeater buttons and if they are loaded via ajax use something like this to attach the event handler:
$(document).on('click', '.repeaterButton', function(e) {
var valueOfBtnClicked = $(this).val();
// Do something else
});
This is my task . I have to create a master page and its two child pages. Details are below
Declare 3 session variables in master page.
Pages_viewed
ChildAppData1
ChildAppData2
Declare 1 session variable in each child application
ChildVar1
ChildVar2
Once the child application loads
Pages_viewed ++;
Set ChildVar1 = ChildAppData1 = datetime.now(); or ChildVar2 = ChildAppData2 = datetime.now();
Add a button to the master page that resets ALL variables.
Display all 5 variables in master page as well as active child application.
I have to show the no of times a child page is visited in page_viewed variable.
Simplest way is to Redirect to self with some information/command in the get parameter to self page.
like Default.master enclosing
Default.aspx
->Redirect to
`Default.aspx?cmd=clearAllVariables`
On Page_Load check
if(!PostBack && (Request["cmd"] != null) && (Request["cmd"].ToString() == "clearAllVariables"))
{
clearAllVariablesImplementation();
}
I have Created form with Server Side control like button..and also have written event on that..
Now runtime after click on the button i have refreshed the page by pressing F5.Page_load is executing fine but button1_click() event also firing...So how can i stop this event execution in this scenario.Please suggest me
Short Answer: Not possible
Longer Answer: No web site can block the browser's functionality as that would be a serious security concern for the browser.
Welcome to web development, there is no way to stop the page from refreshing and reposting, this is entirely a browser behavior.
There are work arounds though; one simple thing that you can do is after processing your button click, you can redirect the browser back to the page so that a refresh will not include a repost of your button press. Obviously this might require some other state management system (rather than view-state), maybe you can store your state in the Session.
<script type="text/javascript" language="javascript">
function checkKeyCode(evt)// for F5 disable
{
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if (event.keyCode == 116)//disable F5
{
evt.keyCode = 0;
return false
}
if (event.keyCode == 123) {
evt.keyCode = 0;
return false
}
if (event.keyCode == 93) {
evt.keyCode = 0;
return false
}
if (event.altKey == true && event.keyCode == 115) //disable alt-F4
{
evt.keyCode = 0;
return false
}
//alert(event.keyCode);
}
document.onkeydown = checkKeyCode;
</script>
Post this script on your master page or where u want to block F5 button.
You could potentially use:
window.onbeforeunload = function ()
{
return false;
}
This will display a prompt asking the user if they want to navigate away and may not be desired. (Plus, I don't know the extent of support)
The poster is using ASP.NET WebForms. In MVC, using the Post-Redirect-Get pattern, this would not be a problem.
But this has been solved for Webforms since 2004 (and even before that - I wrote a simple ticket solution in 2001) with this article: http://msdn.microsoft.com/en-us/library/ms379557.aspx
Basically the author creates a unique ticket associated with each request, and removes the validity of the ticket on first postback. Any accidental (or malicious) subsequent postbacks are ignored. It's wrapped up in a base page so it should be easy to add to any Webforms solution.
Its not really page refresh that you want to block, its page re-POST.
As already said, it's not possible on the client side because the refresh will replay what the browser did on the last action.
But you can trap it on the server side because the server can hold some infos to control the request.
The easiest way is to put a sort of RequestID in a hidden field on Page Load, store it somewhere like in the Session. And control its value on next POST to valid the request then override it to avoid re-POST with the same RequestID.
Maybe there's a better way :)
Your 'problem' is similar to a user double-click horror behavior : ASP.Net double-click problem
Do you have to refresh the page on the click of the button? Could you rewire the button to make an ajax call to submit the data? If so, then you would not need to worry about the page re-submitting on refresh.
The only solution for the F5 refresh problem is Response.Redirect. Please see my post on this topic.
https://stackoverflow.com/questions/12596152/asp-net-f5-browser-refresh-duplicate-record/12596153#12596153
I got some code that doesn't allow you to press F5 and/or Ctrl + R:
<!DOCTYPE html>
<html>
<head>
<title>
Key code test!
</title>
<script type="text/javascript">
var x, ctrlKeyPressed = false;
function keyDown(e){
x = e.charCode || e.keyCode;
document.getElementById("key").innerHTML = x;
if(x == 17) {
ctrlKeyPressed = true;
}
if(ctrlKeyPressed && x == 82) {
e.preventDefault();
} else if(x == 116) {
e.preventDefault();
}
}
function keyUp(e) {
x = e.charCode || e.keyCode;
if(x == 17) {
ctrlKeyPressed = false;
}
}
window.onload = function () {
document.onkeydown = function (e) {
keyDown(e);
};
document.onkeyup = function (e) {
keyUp(e);
};
}
</script>
</head>
<body>
Press a key!
<br/>
Key code: <div style="display:inline;" id="key">Nothing</div>
</body>
</html>
if (TextBox1.Text == row["UserName"].ToString()
&& TextBox2.Text == row["Password"].ToString())
{
//here i have to reload the page
Button1.Attributes.Add("onclick", "alert('Login SucessFull')");
break;
}
Maybe this is more what you want? It will show an alert and then redirect you to another page.
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LoggedInScript", "alert('Login SucessFull'); window.location = 'MyLoggedInPage.aspx';", true);
When you say you need to "reload the page" do you mean redirect to another page becuase the user is now logged in? If you you use:
Response.Redirect("MyLoggedInPage.aspx")