Loading external <Div></Div> to Iframe - javascript

In my project am using a master page named as master.aspx in particular page i need to include another page into the current page, so that i use <iframe> to achieve this. while passing the url to the iframe the master page will also load inside the <iframe> how can i avoid such loading of master page inside the iframe?
i can't avoid master page in the page which i called, is it possible to call particular <Div> or <content template> in iframe?

seems you are using asp.net, maybe you can try to edit the first row in .aspx page, try to add the following code to the page which you don't want to show the master page.
Theme="" StyleSheetTheme=""
==== Update ====
if you want to hide it in iframe only, you should pass a parameter in url like ?theme=none
then handle it in the Page_load Function in .aspx.cs as follow:
protected void Page_Load(object sender, EventArgs e)
{
if(Request["theme"] == "none"){
Page.Theme = "";
Page.StyleSheetTheme = "";
}
}

Related

Inject a Javsacript SDK to several selected pages

I have an ASP.NET web application and I want to inject a JavaScript SDK to several selected pages during the page load of one specific page(for example HomePage.aspx).
I was thinking of a method like this to call on Page_Load of HomePage.aspx
injectScript(list of selected pages, script){
for each page in selected pages{
page.embed(script)
}
}
But can we use Page.ClientScript.RegisterStartupScript() to register scripts for other pages while calling it from HomePage.aspx?
Is there any better way?
Update 1:
In nutshell, All these pages share a master page but adding this JavaScript SDK to master page will make the SDK available to all child pages. I want to have a way to toggle(on/off) this SDK in each page based on user input(saved in a database).
There are more than 30 aspx pages and adding a method to page_load in each page is not feasible.
Is there any simple way to do achieve this functionality?
In case if anyone wondering the same, here is the solution I came up; use the following method inside Page_Load of the master page.( You will have to populate the list with appropriate data-source)
private void EnableSDK()
{
List<string> pages = new List<string>(); //selected aspx page names(not class names)
foreach (string page in pages)
{
if (page == System.IO.Path.GetFileNameWithoutExtension(Page.AppRelativeVirtualPath))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "somekey", "somescript", true);
}
}
}

LinkButton click doesn't trigger with no javascript

Web forms user control generating a LinkButton in PageInit:
LinkButton b1 = new LinkButton();
b1.Click += new EventHandler(Button_Click);
public void Button_Click(object sender, EventArgs e) {
//redirects to another page .. (no js defined here or in the ascx surrounding this button)
}
Why doesn't this wok when my javascript is disabled, if I used no js at all when creating the button?
How do I prevent this?
Yes this is webforms (sorry, unable to comment below).
The issue is that's how web forms manages its events with the server - as I understand it anyway (correct me if I'm wrong). Use html 5 instead. You can make the page postback to the server at the same url with a query string and then on the server grab the query string. Not the best solution but it works; it will look something similar to this:
In your page:
<form id="aForm">
<button id="abutton" type"submit" formaction="thisPage.aspx?redirect=true">click me</button>
</form>
In your page load event on the server:
if (IsPostBack) {
object something = Request.QueryString["redirect"];
if (something == null)
//not redirecting
}

jQuery call error on Page_Load

I have the following code to register a javascript function on Page_Load (also tried it on Page_Init). The javascript switches two panels from hidden to shown based on a parameter on load of page:
protected void Page_Load(object sender, EventArgs e)
{
String switchAction = "<script language='javascript'>switchactionpanel(" + (int)((Global.upAction)Enum.Parse(typeof(Global.upAction), Global.ProfileAction.ToString())) + ")</script>";
Page.RegisterClientScriptBlock("switchaction", switchAction);
}
But when the page loads I am receiving an error: $ is not defined.
I looked in Firebug and the jQuery files are being loaded however, the first file that is being loaded in the .Net tab is the page itself. I know the jquery is correct as the same code works on a different page. Where should my RegisterClientScriptBlock be put in the page lifecycle to work correctly when the page loads? Or am I going about this all wrong?
You just need to ensure that the inserted script gets inserted after the JQuery reference.
Use RegisterStartupScript instead -- that inserts the script tag before </form> closing tag.
Not sure if this is relevant but I always use:
<script type="text/javascript"...
Sorry this should have been a comment rather than an answer.
I think it has to do with the register function your using. Try using RegisterStartupScript instead of RegisterClientScriptBlock.
Page.ClientScript.RegisterStartupScript(this.GetType(), "switchaction", "<script language='javascript'>switchactionpanel(" + (int)((Global.upAction)Enum.Parse(typeof(Global.upAction), Global.ProfileAction.ToString())) + ")</script>", false);

Changing window parent url from child not changing complete url

From my child window Im trying to refresh the parent window. I tried several js functions refresh or change the parent window url and non of them gave me what I needed.
alert(window.opener.location.href); //gave null
//all the functions bellow changed the url to
// http://mydomain/www.google.com
window.opener.location.assign("www.google.com");
window.opener.location.replace("www.google.com");
window.opener.location.href = "www.google.com";
window.opener.location = "www.google.com";
I also tried parent.location.href but didnt change the parent url.
Is there a way I can set the parent url to the desired url? or just let it refresh the page ?Any ideas?
EDIT
I cant post sample code because What Im doing is a bit complicated. Im using a salesforce button that calls a new window (asp.net page). I dont have much access to that page other than the .aspx page. Its a compiled version of a project we bought. In the .aspx page Im trying to call a js function because I dont have access to the code behind of that page. My js function is supposed to refresh the parent page once the user press on either (yes or no).
<cc1:ImageButton ID="btnNo" runat="server" OnClick="btnNo_Click"
OnClientClick="pop()" Text="No" Width="40px" />
<script type="text/javascript" language="JavaScript">
function pop(){
window.opener.location.reload(true);
//window.opener.location.href = "www.google.com";
}
</script>
This should work:
window.opener.location.reload(false);
EDIT
Based on your comments, it sounds like your violating the Same Origin Policy.

Load Applet via Javascript function on the same page

I am trying to load an applet on demand via javascript.
Here is what I've tried:
function startApplet() {
document.write('<applet code="com.pwc.envoyapp.applet.SampleApplet" height=30 width=40 archive="ucfapplet.jar"></applet>');
}
The problem is that it loads the applet in a new page. I need it to open it on the same page so that session keys generated by the applet are preserved.
Is there a way to get the applet to load on the same page?
have you tried something like:
document.getElementById("appletContainer").innerHTML = "<applet ... />";
of course you'd need the element to exist so somewhere in your DOM you'd have:
<div id="appletContainer"></div>
as an empty element waiting to be populated.

Categories

Resources