Is it possible from c#/asp.net to call/show a separeted html-page in the same window.
I don't want to store the entire html code into a
, for exemple...
(that works).
Possible with javascript? or do I have to modify the code-behind?
The purpose is to load this html page everytime the default.aspx is invoked, as a webform(pop-up)
You can Use iframe to open your .html page as:
.aspx Page:
<iframe id="ifrm" runat="server"></iframe>
And on Page_Load(code behind):
protected void Page_Load(object sender, EventArgs e)
{
ifrm.Attributes["src"] = "yourHtmlpageURL.html";
}
You can use it asp.net
<iframe src="http://www.google.com"></iframe>
For c# application you can use WebBrowserControl.
Related
i have webapplication. In my master page i have few link buttons which are as below
<asp:LinkButton ID="link1" runat="server" OnClick="linkAge_Click">Age</asp:LinkButton>
<asp:LinkButton ID="link2" runat="server" OnClick="linkName_Click">Name</asp:LinkButton>
In my Visual studio i have seperate folder called Age and Name and under those there are default.aspx.
on click event of link button i have this code
protected void linkAge_Click(object sender, EventArgs e)
{
Response.Redirect("/Age/");
}
protected void linkName_Click(object sender, EventArgs e)
{
Response.Redirect("/Name/");
}
In IIS i added Application called "Test" and then added all code inside it
When i browse i get to master page as http://localhost:80/Test
When i click on link "Age" the url Changes to http://localhost:80/Age
I expected it to be http://localhost:80/Test/Age
What is wrong that i am doing? Can i achieve this without using any code changes.
Try to use http://localhost/Test/ (with slash in the end) link in to Your browser.
You need to add a tilde (~) to get URLs relative to application root:
Response.Redirect("~/Age/");
BTW: Why do you need to have the redirect behind a post-back? You could use <asp:HyperLink> instead
Like we do this in mvc to get path from root - Url.Content("~\Action\")
In web form -
protected void linkAge_Click(object sender, EventArgs e)
{
Response.Redirect(Server.MapPath("~/Age/"));
}
You got to think like this i think.
Since you're using only the /Age/ path, with nothing to indicate that you're using a relative path. For code managed by IIS, you'd use ~/Age/Whatever to indicate that you intend to go to Age relative to Test.
I'm fairly new to ASP.NET, I've been reading a few questions related to this but I'm still unable to figure out what's wrong with my code, I have a default.aspx page with a menu on top created using a list (ul and li items) and putting the <a href=""> tag to create the links to other pages but after following a link to another page, the Page_Load event fires before leaving the page, I understand this would be the expected behavior with Response.Redirect, but I don't know how to avoid this using tags (if possible), this is the markup I'm using for the Default.aspx page:
<ul id="lista">
<li><strong>Inicio</strong></li>
<li><strong>Item</strong></li>
<li><strong>IK</strong></li>
<li><strong>Acerca de</strong></li>
</ul>
And this is the code behind I have for Page_Load:
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
ExcelUtility excel = new ExcelUtility();
dtDefault = excel.LeerExcel();
gridResults.DataSource = dtDefault;
gridResults.DataBind();
gridResults.VirtualItemCount = dtDefault.Rows.Count;
}
}
Basically, what I want to do is to follow the link to some other page without loading the default page before leaving, hope I make myself clear!
Edit: The root cause of this was having the default <form runat="server"> tag at the beginning of the body section, this was causing the Page_Load event firing again in the same page once the links were being clicked, placing the hyperlinks outside of the form tag did the trick.
Your HTML code should be inside some HTML tag or custom ASP control which contains the attribute runat="server". This is supposed to fire a PostBack request to the server.
I am needing to use the same form for displaying multiple things and I realize that when I add links like:
A
it has the same form and web address, but with a #A at the end of the address.I thought I could use this for displaying multiple things on the same form. My idea is to have C# code in the page_load method to detect what the web address is and use a conatins method for the url string and detect if there is #A to change the content of the form. Here is an example:
C# code:
protected void Page_Load(object sender, EventArgs e)
{
string url = HttpContext.Current.Request.Url.AbsoluteUri;
if(url.Contains("#A"))
{
div1.Visible = false; //content 1
div2.visible = true; //content 2
}
}
asp.net code:
A
<div ID="div1" runat="server">
content 1
</div>
<div ID="div2" runat="server">
content 2
</div>
I have tried to put the Page_Load method in a script tag, but still didn't work. I guess since the url is different the cs code is not valid? I know it goes through the page_load method once, before I click on the link. Also I do use a method that gives me the controls of div1 and div2, so that is not the problem. I thank everyone in advance for your help! Also if my way is not the way to do the job then please tell me any way possible to achieve what I am trying to do.
edit: I can't use a button to replace a link... maybe a asp:hyperlink?
That's an HTML hyperlink you're using and it won't cause a postback thus page_load will never get called when you click it.
I would suggest if you want to show an hide divs that you use client side JavaScript. Alternatively you could (for example) use an asp.net button control which will cause a postback.
I would suggest scrapping the anchor with an href approach in favor of this:
Use the ASP.NET server controls, along with their click event handlers to manage the visibility of controls on your page.
In your Page_Load, make it so the page has an initial state of showing controls, like this:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
div1.Visible = false; //content 1
div2.visible = true; //content 2
}
}
Now instead of an anchor tag, you can use an ASP.NET Button or LinkButton to cause a postback to the server, like this:
<asp:Button id="Button1"
Text="Click here to change page to B"
OnClick="Button1_Click"
runat="server"/>
Now you have the event handler code which would change the visibility of controls, like this:
protected void Button1_Click(Object sender, EventArgs e)
{
div1.Visible = true; //content 1
div2.visible = false; //content 2
}
I am working on a project for school, and this is an extra credit part. I have a project started in VS 2010 using master pages, and what I'm trying to do is get a "Submit" button to redirect people to the "MyAccounts.aspx" page. My current code for the ASP part for the button looks like this:
<asp:Button ID="btnTransfer" runat="server" Text="Submit"/>
I have tried adding in the OnClick option, as well as the OnClientClick option. I have also added this code to the Site.Master.cs file as well as the Transfer.aspx.cs file:
protected void btnTransfer_Click(object sender, EventArgs e)
{
Response.Redirect(Page.ResolveClientUrl("/MyAccounts.aspx"));
}
When I run this and view the project in my browser, the whole thing runs fine, but when I click on the "Submit" button, it just refreshes the current page and does not properly redirect to the MyAccounts page. Anyone have any ideas for me?
You are doing it almost correctly, you just haven't put the correct pieces together. On Transfer.aspx, your button should be:
<asp:Button ID="btnTransfer" OnClick="btnTransfer_Click" runat="server" Text="Submit"/>
and your code behind should be like what #KendrickLamar said:
protected void btnTransfer_Click(object sender, EventArgs e)
{
Response.Redirect("~/MyAccounts.aspx");
}
The OnClick event tells it what to execute on post-back when the users clicks the button. This is in the code-behind for Transfer.aspx, not the site master.
I have a modal popup inside of an update panel with a silverlight control.
The video displays fine in IE 7/8 but in firefox all I get is a white screen
I am using the following video skin from link text
<div style="height:360px;">
<asp:Silverlight
ID="myVideoPlayer"
runat="server"
Source="~/Videos/VideoPlayer.xap"
Width="640px"
Height="360px"
InitParameters="m=Efficiency.wmv"
Windowless="true" />
</div>
I know it works when I use the normal <object> method but that will not work as I need to set the Initparams from the code behind depending on what video category they choose.
I have consulted the google gods and they have been not so helpful. Hope you guys can help me with this problem. Thank you!
I use Object tag, and init params injected to aspx like this :
<%= initparams %>
initparams is protected variable of my Page class:
public partial class _Default : System.Web.UI.Page
{
protected string initparams;
protected void Page_Load(object sender, EventArgs e)
{
initparams = "m=video.asx";
}
you can also change that variable in any event, it will be injected to rendered HTML.