How to assign HTML content to iframe control from asp.net codebehind? - c#

I want to assign the html content to iframe control from asp.net code behind page;
this is working fine
myIframe.Attributes.Add("src", "pathtofilewith.html");
but, i don't want to give the path of html file to display i just want to assign some html content which comes from database to iframe control.
i want some thing like this(Ashok) to be displayed in iframe control
i tried the bellow ways but nothing is succesful
myIframe.Attributes["innerHTML"] = "<h1>Thank You..</h1>";
myIframe.Attributes.Add("innerHTML", "<h1>Ashok</h1>");

A way to communicate between two different pages where one is in an IFrame on the other, is to post data using JQuery. An example is given in this StackOverflow question
It is also discussed in this other StackOverflow question
On this page, you will also find a short and simple example of how you can put content in an IFrame without using a separate web-page for it (note the lacking src attribute!).
Hope some of this helps!

You can't. That's not how an IFRAME works - it is for use with the src attribute as you've already discovered.
Perhaps you want to create a DIV instead

There is no way to insert HTML content into iframe tag directly, but you can create a page which gets the content form the database and then you can view it using iframe,
or
You can create a page for example called getContent.aspx which request value from the URL e.g. getContent.aspx?content=<h1>Thank You..</h1> and display it wherever you like, and then call it from iframe.

Related

Include HTML webform in ASP/C# on page load

I made a webform in html and I have a website in C#.
I would like this form to show up every time the page is loaded.
What is the best way to integrate/include/call the form?
Which pages I have to modify? Default.Aspx or Default.Aspx.cs?
The purpose of this project is to show this form everytime the cookies is not set in the aspx code.
Which I guess I have to modify the aspx part that checks if the value of the cookie is set or not and show/not show the webform based on this value.
You could do this using a combination of JavaScript (to check if cookies are enabled) and JQuery. If cookies aren't enabled, have a placeholder DIV that can hold the HTML content you wanted to show. Then use $.ajax (http://api.jquery.com/jquery.ajax/) to load the html content from browser and set the DIV's innerHTML property with the returned HTML.
Hope this works for you!!
Some little progress.
That's how I modified my pages for my needs. In this way the html webform is diplaying correctly.
In the head of default.master I added:
in the default.aspx I added:
with the entire html of my html page (tag html included).
Now I need to modify this page that in the way this pop up is showed only if a cookie value is not set.

Use RegisterStartupScript to place HTML at the bottom of the page?

I tried using Page.ClientScript.RegisterStartupScript to place HTML or invisible elements at the bottom of my page and this seems to be working fine. Is there anything wrong with this as the RegisterStartupScript was intended for JavaScript only?
<asp:ContentPlaceHolder> is the correct control to use to "place HTML or invisible elements at the bottom of my page"
The problem you'll most likely encounter with this approach is that when using the UpdatePanel, you should be calling ScriptManager.RegisterStartupScript() instead. This will depend on the structure of your page (eg, are you registing the script from within a UserControl), and what your javascript is doing
What you've done is not something to be taken as a best practice, but I believe it should not cause you any problem. What the ScriptManager and the ClientScript do, is just append the specified content to the output HTML that is going to be sent to the browser.
However, you can consider to achieve this by placing place holder control at the bottom of the page and then append your HTML content to that holder.

how to show two web pages in one window without frames

I want to show a web page within another web web in asp.net. I have a page named home.aspx and a page name add.aspx how can i do this.
if you just want to load contenct than make use of jquery ajax function or noraml ajax to load data in you page
Example
$("#result").load("AjaxPages/Page.aspx", function () {
alert("Page.html has been loaded successfully!")
});
Use iframes. Pleace for example this code inside the homep.aspx. This is only the idea, find how to show it with out border and with out scrool bars, and also how to fit it in place.
<iframe src="add.aspx"></iframe>
http://www.w3schools.com/tags/tag_iframe.asp
http://htmlhelp.com/reference/html40/special/iframe.html
ajax and iframe
Use ajax if you have some informations only to show. Use iframe if you also need independend post backs that enters data.
ajax is better if you care to have only one page, not working with out javascript, and maybe you need to add more ajax to make more thinks with the data that you get.
iframe is fast, but 'dirty' because is not seo friendly, a user can open content from iframe alone, etc.

Parsing out a hidden field inside iframe using HtmlAgilityPack .NET

I'm having problems picking out data I need that's inside an iframe form. Is it even possible using HtmlAgilityPack? Here's a screenshot using Firebug so it's easier for you guys to see.
http://i.stack.imgur.com/ftt84.jpg
I need to parse out the post_form_id. I've tried
var value = doc.DocumentNode.SelectSingleNode("//input[#type='hidden' and #name='post_form_id']")
.Attributes["value"].Value;
but obviously won't work because it's inside the iframe form. Appreciate any help.
I would
Use the HTMLAglityPack to find the iframe location
Use the System.URI class find the absolute link of the iframe page
Open this iframe page
Use HTMLAglityPack again on the iframe page to find the required information

Master Pages ASP.net in C# adding dynamic flavor

I need to have a button on the master page.
Once that button is clicked I generate a string that represents URL.
test.apx is a content page I use and the string will look like something like this:
Example:
www.blah.com/test.aspx?user=blax&develop=extreme_all
Now all I need is to reload the page while content is redirected to the URL I generated.
I hope this makes more sense.
Thanks guys I am new to asp.net and really appreciate any help
Why dont you use Update Panel?
Have the page postback with the updated query string to change what is in your content area
Assuming your masterpage is set up correctly
within the <asp:content> tag of your aspx page that is using the masterpage you created add code to get the query string
Request.QueryString["key"]
example url: http://www.whatever.com?foo=bar&bar=foo
string tmp = Request.QueryString["foo"]
tmp will become "bar"
Now just check the "postback" option of the asp:control you're using to reload the content page or do whatever you to make the page refresh.
If I understand your question correctly, you want to reuse the same code to parse out your user and develop variables from different content pages that use the same master page.
It sounds like you need a strongly typed master page.
First, put your shared code in your master page. Then, expose the parsed data as properties of the master page. Next, simply add the following directive in your content pages:
<%# MasterType VirtualPath="~/mymasterpage.master" %>
Finally, in your content pages, you can reference your properties as such (assuming you created a property called MyUser):
string user = this.Master.MyUser;
You can also use inheritance if you want a different approach. Simply create class that inherits from Page. Then put your shared code in that class. Finally, make your content pages inherit from your new class, instead of Page.

Categories

Resources