Is it possible to perform a response.redirect within an iFrame to redirect the whole page so that the destination page is viewable full screen and not contained within the iFrame?
Below is the current code behind
public partial class ServerResult : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Any help would be much appreciated :-)
No.
Response.Redirect is a server command which sends (302 ?) header tells the client to redirect.
you are in the iframe world. you can't tell the server: "Hey , when you send me data - send it to the parent Iframe"
BUT What you can do , is this :
protected void Page_Load(object sender, EventArgs e) {
ClientScriptManager.RegisterClientScriptBlock(this.GetType(),
"aaa", "window.parent.location = 'http://yoursite.com'", true);
}
but you have to remove response.redirect from server.
Edit
var page = HttpContext.Current.Handler as Page;
if (page != null) page.ClientScript .RegisterClientScriptBlock(typeof(string), "Redirect", "window.parent.location='" + url + "';", true);
Related
i have made a textbox that gets it's text from a variable linked to a database.
ee from class employee and s from class general both work, and the data inside ee is correct.
when the page loads, the textbox does show the data inside ee.Field but when i change it and click save it doesnt change and doesnt save the new data in my database , i know for sure the the functions.fieldChange() works and that for some reason it doesnt get into the if(field.text!=ee.Field) (i have checked it using a simple label text change).
here is my html:
<asp:TextBox ID="field" runat="server"></asp:TextBox><br />
<asp:Button ID="Save" runat="server" Text="Save" OnClick="saveChanges" />
my asp.net:
string User;
Genral s = new Genral ();
public Employee ee;
protected void Page_Load(object sender, EventArgs e)
{
User = Session["User"].ToString();
ee = s.getEmployee(User);
this.field.Text = ee.Field;
}
protected void saveChanges(object sender, EventArgs e)
{
if (field.Text != ee.Field)
{
s.fieldChange(User, field.Text);
}
}
What doesnt it work? Thanks for the help
You need to check ispostback property in page load, when you hit save button it first called postback so it replace the value with the old one and your newly inserted data lost.
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
User = Session["User"].ToString();
ee = s.getEmployee(User);
this.field.Text = ee.Field;
}
}
Im doing a cloud App(like Skydrive) in Windows Phone 8 , each time I navigate to a different folder I need to reload the FolderView.xaml page to display the content of this folder and I need to add the view to the back stack then I will be able to back to the previous path...
From now when I try to reload the FolderView from the FolderView.xaml.cs page, none event is called...
I don't understand why ? And if you have a solution you are welcome ...
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
if (App.ElementSelected != null)
{
BdeskElement FolderChoosen = new BdeskElement();
FolderChoosen = App.ElementSelected;
Gridentete.DataContext = FolderChoosen;
GetFiles(FolderChoosen);
}
}
private async void llsElements_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LongListSelector llselement = null;
listElementCollection.Clear();
if (sender != null)
llselement =(LongListSelector)sender;
if(llselement.SelectedItem!=null)
{
BdeskElement bdelement=(BdeskElement)llselement.SelectedItem;
if (bdelement.TypeElement==BdeskElement.BdeskTypeElement.Folder)
{
App.DocLibSelected = null;
App.ElementSelected = bdelement;
// I navigate to the same view here but nothing happens
NavigationService.Navigate(new Uri("/Views/BDocs/FolderView.xaml", UriKind.RelativeOrAbsolute));
}
}
}
To navigate to the same page with a new instance, you must change the Uri. For example:
NavigationService.Navigate(new Uri(String.Format("/Views/BDocs/FolderView.xaml?id={0}", Guid.NewGuid().ToString()), UriKind.Relative));
You can discard that parameter if you don't want/use it.
I have .html file inside a directory "/country/main.html". Now, I want to redirect the user to this page whenever a request arrive for any country. I have written a little code snippet
public class Global : System.Web.HttpApplication
{
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
if (app.Request.Path.Contains("/country"))
{
app.Context.RewritePath("/country/main.html");
}
}
}
I tried this url http://www.mydomain.com/country, that works fine. But if the request arrive something like this http://www.mydomain.com/country/new_york.html, it gives me 404 error.
Please suggest, what I have to do in that case?
customer use http://aaa.com/uploads/bb/index.html to request my ASP.NET MVC site. I want to make sure the customer has enough permission to access the site, so I need catch the request and deal with it. I'm using IHttpModule to do that.
public class myHttpModule : IHttpModule {
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
Uri url = application.Context.Request.Url;
string path = url.AbsoluteUri;
}
}
the question is when second time use the same url to request the website, the HttpModule can't catch the request.
got the answer!It's about the http cache.
I write code as below and the problem was killed:
public class myHttpModule : IHttpModule {
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
Uri url = application.Context.Request.Url;
string path = url.AbsoluteUri;
**app.Response.Cache.SetCacheability(HttpCacheability.NoCache);**
}
}
I need to load a specific webpage from a site that has multiple images on the site. I need to extract these images but I can't do this manually because the names of each image have no pattern and there will be hundreds of sites. I have a silverlight application to load the webpage in an iframe and I intended on extracting the html for this webpage and then retrieving the image source for each image from the extracted code and then populating a listbox.
I can load the web page in iframe with no problem, but I don't know how to retrieve the html code for the webpage.
public Page()
{
InitializeComponent();
System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("ifHtmlContent");
if (myFrame != null)
{
myFrame.SetStyleAttribute("width", "1024");
myFrame.SetStyleAttribute("height", "768");
myFrame.SetAttribute("src", txtURI.Text);
myFrame.SetStyleAttribute("left", "0");
myFrame.SetStyleAttribute("top", "50");
myFrame.SetStyleAttribute("visibility", "visible");
}
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.Button_Click(sender, e);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("ifHtmlContent");
if (myFrame != null) myFrame.SetAttribute("src", txtURI.Text);
}
private void txtURI_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
this.Button_Click(sender, e);
}
The following article may offer some help:
http://jesseliberty.com/2010/05/03/screen-scraping-when-all-you-have-is-a-hammer/