My html page is
<iframe runat="server" id="iframe1" width="100%" height="100%" scrolling="no" frameborder="0"></iframe>
.cs content in my pageload event
iframe1.Attributes["src"] = "http://default.com/";
//iframe1.Attributes["height"] = "100%";
//iframe1.Attributes["width"] = "100%";
iframe1.Attributes.Add("style","width:100%;height:100%;");
But its not working
i want to display whole page content but my height of iframe is not taking the height of http://default.com/
I don't know how to autoresize iframe on .cs page but It's another option like put your iframe in datalist control like...
<asp:DataList ID="dtlhtml" runat="server" Width="100%">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<iframe src='<%#Eval("html") %>' width="713" id="iframe1"
frameborder="0" onLoad="autoResize 'iframe1');">
</iframe>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
Put javascript code as...
<script language="JavaScript">
function autoResize(id)
{
var newheight;
var newwidth;
if (document.getElementById(id))
{
newheight = document.getElementById(id).contentWindow.document.body.scrollHeight;
newwidth = document.getElementById(id).contentWindow.document.body.scrollWidth;
}
document.getElementById(id).height = (newheight) + "px";
document.getElementById(id).width = (newwidth) + "px";
}
</script>
And put on .cs page.
DataTable dt1 = new DataTable();
dt1.Columns.Add("html");
DataRow dr = dt1.NewRow();
dr["html"] = "";//Any dynamic url path
dt1.Rows.Add(dr);
dtlhtml.DataSource = dt1;
dtlhtml.DataBind();
NOTE:
This will not work in local host ..please try it on online.
I assume you don't want 'scrolling', so why not disable it?
<iframe src="/default.asp" width="100%" height="100%" scrolling="no"></iframe>
or try
iframe1.Attributes.Add("scrolling","no");
Edit: Try
PlaceHolder1.Controls.Add(new LiteralControl("<iframe src='mypage.aspx' width='100%' height='100%' scrolling='no'></iframe>"));
or
iframe1.Attributes["src"] = "http://www.asp.net";
Since you are using runat="server" so you can access the attributes like height and width from code behind.
Try
Updated Answer
iFrame1.Attributes.Add("height","100%");
iFrame1.Attributes.Add("width","100%");
set scrolling ="no" inside tag as suggested by Paul
Related
I am trying to get the image button in this table to get hidden via the code behind in C# (so that I can hide it after an action).
<asp:UpdatePanel runat="server" ID="upEmpListContainer" UpdateMode="Conditional"
OnPreRender="upEmpListContainer_PreRender" OnInit="upEmpListContainer_Oninit">
<ContentTemplate>
<asp:ListView ID="lvEmpList" OnItemDataBound="lvEmpList_ItemDataBound" OnDataBound="lvEmpList_DataBound"
OnLayoutCreated="lvEmpList_LayoutCreated" runat="server" OnPreRender="lvEmpList_PreRender">
<LayoutTemplate>
<table class="formData_tb" cellspacing="0" style="margin: 0px; width: 100%;">
<tr>
<th colspan="9" class="currentManagerLabel" style="text-align: center">
<span>Currently displaying
<asp:Label ID="lblManager" runat="server" />
employees </span>
<asp:ImageButton ID="DrillUp" AlternateText="Move up in reporting heirarchy" runat="server"
CommandName="DrillDown" ImageUrl="~/images/icoDoubleArrowUp.gif" OnCommand="butDrillDown_Click" />
</th>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
I just can't seem to access it from its ID. I've tried DrillUp.Enabled = false; but Visual Studio is saying that it can't resolve symbol 'DrillUp'.
Your imagebutton is inside layout template, you cant access it directly.
Try this
ImageButton b = (ImageButton)lvEmpList.FindControl("DrillUp");
b.Visible = false;
In your code behind method lvEmpList_ItemDataBound, you need to use the following:
((e.Item.FindControl("DrillUp")) as ImageButton).Visible = false;
Also, you should add a check that this is done only for the DataItem items like this:
if (e.Item.ItemType == ListViewItemType.DataItem)
{
((e.Item.FindControl("DrillUp")) as ImageButton).Visible = false;
}
Try to:
1-remove that imagebutton from aspx
1-clean the solution
2- Write manually again that asp:imagebutton...
It will work fine
How can I find an ASP.Net table control with FindControl method?
if (Convert.ToInt32(Session["Persons"]) == 1)
{
HtmlTable tt = (HtmlTable)panel1.FindControl("singleTbl");
tt.Visible = true;
}
<asp:UpdatePanel ID="panel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn_serch" EventName="Click" />
</Triggers>
<ContentTemplate>
<div id="div_result" runat="server" style="display:none" class="divsearchresult">
<table width="750">
<asp:DataList ID="dtlRoomsPrice" Visible="false" orizontalAlign="center" runat="server"
ShowFooter="False" ShowHeader="False" Width="700px" OnItemDataBound="dtlRoomsDetails_ItemDataBound">
<ItemTemplate>
<table border="0" id="singleTbl" width="90" align="left" runat="server" style="visibility:hidden;">
</table>
</ItemTemplate>
</table>
</div>
</asp:UpdatePanel>
There are some problem with your code ,
First you can not cast an ASP.Net control to HTML control or vise versa
so your table is HTML control you need cast it to HtmlControl like:
HtmlControl tt = (HtmlControl)FindControl("singleTbl");
tt.Visible = true;
second you have designed a table HTML tag which have not any tr and td so change it like :
<table border="0" id="singleTbl" width="90" align="left" runat="server" style= "display:none;">
<tr>
<td></td>
</tr>
</table>
It is proffered to use display instead of visibility because display:none; hides an element, and it will not take up any space so you can try like:
HtmlControl tt = (HtmlControl)FindControl("singleTbl");
tt.Style.Add("display", "block");
//tt.Attributes["visibility"] = "visible";
//tt.Attributes["display"] = "block";
//tt.Visable = true;
or you should do it in ItemDataBound event of DataList as following:
HtmlControl tt = (HtmlControl)e.Item.FindControl("singleTbl");
tt.Style.Add("display", "block");
The method "FindControl" searches the first level controls under the container . Maybe your table is enjected dynamically after a postback or it 's under an other control like Panel or UpdatePanel.
First of all your table is a HTML table so singleTbl is a HtmlTable not Table.
If you want it a Table Class you must use <asp:Table> tag.
Second point your tag <contenttemplate> is not closed.
The last point, i mentioned that the FindControl sheaches only in the direct children of the control.
you must add runat server and an Id to your first div and table
then in your code:
var div= Panel1.FindControl("divID") as HtmlGenericControl;
var firstTable=div.FindControl("firstTableID") as HtmlTable;
var dataList=firstTable.findControl("dtlRoomsPrice") as DataList;
var tbl=dataList.FindControl("singleTbl") as HtmlTable;
my html code is
<script language="JavaScript" type="text/javascript">
function autoResize(id)
{
var newheight;
var newwidth;
if (document.getElementById)
{
newheight = document.getElementById(id).contentWindow.document.body.scrollHeight;
newwidth = document.getElementById(id).contentWindow.document.body.scrollWidth;
}
document.getElementById(id).height = (newheight) + "px";
document.getElementById(id).width = (newwidth) + "px";
}
</script>
<asp:DataList ID="dtlhtml" runat="server" Width="100%">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<iframe src='<%#Eval("html") %>' width="713" height="250" id="iframe1" frameborder="0" onload="autoResize(this.id);"></iframe>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
.cs code on page load event
DataTable dt1 = new DataTable();
dt1.Columns.Add("html");
DataRow dr = dt1.NewRow();
dr["html"] = "";//Any dynamic url path
dt1.Rows.Add(dr);
dtlhtml.DataSource = dt1;
dtlhtml.DataBind();
this is not working in local but working fine on online
Problem
I am running it online on firefox with version 24.0 is running fine but on my 2 friend pc with same version scrolling is coming.
your if condition is incorrect, do as below
if(document.getElementById(id))
{
}
I am not sure though, but I guess problem lies here: Numeric value + string might be causing error.
document.getElementById(id).height = (newheight) + "px";
document.getElementById(id).width = (newwidth) + "px";
You can instead write this as
document.getElementById(id).height = newheight;
document.getElementById(id).width = newwidth;
ALso you can remove 'px' because by default lengths are in pixel only.
Hey my problem is solved as i was giving path as
dr["html"] = "http://stackoverflow.com/file/1.html";
but the proper way was to give path for calling html page to my iframe was to be
dr["html"] ="http://www.stackoverflow.com/file/1.html"
i have a page that has a grid with rows of data and it has url hidden in each row n when a row is clicked it opens new tabed window and the parent page still stays open with the grid data. i want to have a button that does the same . my aspx is
<script type="text/javascript" id="igClientScript">
function NavigateOnClick(sender, eventArgs) {
try {
var row = eventArgs.get_item().get_row().get_index();
var url = sender.get_rows().get_row(row).get_cell(0).get_text();
window.open(url);
}
catch (e) {
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Entity"></asp:Label>
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Select Entity</asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" ID="EntityName"></asp:Label>
<asp:Button ID="newEntity" runat="server" Visible="false" OnClick="newEntity_Click" OnClientClick="aspnetForm.target ='_blank';" />
<ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>
<ig:WebDataGrid ID="EntityGrid" runat="server" Width="100%" Height="50%" StyleSetName="Claymation" >
<Columns>
</Columns>
<ClientEvents Click="NavigateOnClick" />
</ig:WebDataGrid>
</div>
I want something like window.open =(entity,_newtab) without doing a page post back how can i get this?
Just use
window.open(url, 'random_name');
Refer this: http://www.w3schools.com/jsref/met_win_open.asp
Add an attribute to your button:
target="_blank"
button.attributes.add("target","_blank");
here is what worked part of my problem was that the url is dynamic i created a label that is updated on dropdown selection and pass the label text while creating the url instead of asp button went with html button function opentab(sender, eventArgs) {
try {
var name = document.getElementById('EntityName');
var url = name.textContent;
window.open(url+"Edit.aspx");
}catch(e){
}
}which wont cause a postback
If some one have any suggestion or other way kindly help.
I have
1 Textbox
1 Label
1 LinkButton
when I'll click to lnk_NameEdit button txtUserName will visible and lblusername buttons must unvisible and the text in lable will display in TextBox
<td width="237" class="value_td" style="border: 0; border-top: 1px solid #afc0f3;">
<asp:Label ID="lblusername" runat="server" Text="Santosh"></asp:Label>
<asp:TextBox ID="txtUserName" runat="server" Width="300" Visible = "false">
</asp:TextBox>
</td>
<td width="64" class="epotions_td" style="border: 0; border-top: 1px solid #afc0f3;">
<span>
<asp:LinkButton ID="lnk_NameEdit" runat="server" CommandName="Edit" OnClientClick = 'ControlVisible();'>Edit</asp:LinkButton>
</span>|
</td>
<script language="javascript" type="text/javascript">
function ControlVisible() {
var lbl = document.getElementById("<%= lblusername.ClientID %>");
var txt = document.getElementById("<%= txtUserName.ClientID %>");
lbl.visible = false;
txt.visible = true;
}
</script>
<td width="237" class="value_td" style="border: 0; border-top: 1px solid #afc0f3;">
<asp:Label ID="lblusername" runat="server" Text="Santosh"></asp:Label>
<asp:TextBox ID="txtUserName" runat="server" Width="300" Visible = "false">
</asp:TextBox>
</td>
and I have 1 LinkButton
<td width="64" class="epotions_td" style="border: 0; border-top: 1px solid #afc0f3;">
<span>
<asp:LinkButton ID="lnk_NameEdit" runat="server" CommandName="Edit" OnClientClick = 'ControlVisible();'>Edit</asp:LinkButton>
</span>|
</td>
when I'll click to lnk_NameEdit button txtUserName will visible and lblusername buttons must unvisible and the text in lable will display in TextBox
<script language="javascript" type="text/javascript">
function ControlVisible() {
var lbl = document.getElementById("<%= lblusername.ClientID %>");
var txt = document.getElementById("<%= txtUserName.ClientID %>");
lbl.visible = false;
txt.visible = true;
}
try this,
lbl.style.visibility="visible";
txt.style.visibility="hidden";
Assuming the rest of the code is correct, lbl and txt will be dom elements. Dom elements do not have visible properties, but you can hide them by setting their styles' display properties:
lbl.style.display = "none";
EDIT
Make sure you run this code after your dom is ready. That you were getting null from document.getElementById probably means that you were running this script right in your head section. As a result, your dom had not yet been parsed, and your label and textbox didn't exist yet.
The easiest way to fix this is to put the script section at the very end of your body. Another way would be to call ControlVisible from your body's onload: <body onload="ControlVisible()">
There is a big difference between server executed code and client side code.
In the moment you have a mix.
You can set the visibility of an element in client side (javascript) setting the display property
http://www.w3schools.com/jsref/prop_style_display.asp
Take a look at this tutorial: http://www.javascriptkit.com/javatutors/dom3.shtml
You can change this piece og code from this:
lbl.visible = false;
txt.visible = true;
to this:
lbl.style.display= "none";
txt.style.display= "block";
If you are working with server side code (e.g Load event, asp. net button click, etc) you can use the visible property of your object.
Sample fiddle: http://jsfiddle.net/WzTSR/
Your Textbox with ID txtUserName has Visible = "false" which means it's not being sent to the browser - thus you get client side error.
Change this to:
<asp:TextBox ID="txtUserName" runat="server" Width="300" style="display: none;">
Which will still make it invisible by default, then change the lines to:
lbl.style.display = "none";
txt.style.display = "";