Refresh iframe when refreshing page - c#

i have web page it has a page header content like main menu,logo and so..on..
and in iframe i am loading the side menu and content. while loading the web page i am using an empty home page to display. after some time in mid of some page while refresing the page it reloads the home page. But i need to display the page that i am using as a current page
code is
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="vertical-align: top; width: 100%" height="115px">
<div>
<uc1:MainMenu ID="ucMainMenu" runat="server" />
</div>
</td>
</tr>
<tr>
<td>
<iframe src="HomePage.aspx" runat="server" width="1250px" height="675px" id="ifSideMenu"
frameborder="0"></iframe>
</td>
</tr>
</table>
</div>
</form>
in that iframe deafult page is Homepage.aspx,it is empty page. When i clicked the sub menu it loads the content like AddMaster.aspx. When i refresh the page it loads Homepage.aspx, but i need to display AddMaster.aspx
help me

this code will help u to refresh the iframe only.. not the whole web page. but., i dont understand your que clearly brother.
<IFRAME id="frame1" src="http://www.google.com/" runat="server">
<script type="text/javascript">
function refreshiframe()
{
parent.frame1.location.href="http://www.google.com/"
setTimeout("refreshiframe()",3000);
}
</script>
<body onload="refreshiframe();">

I finally found the answer for this question.
It may help for others.
Add the below code in HomePage.aspx and other pages that are going to load in the iframe
Session["CurrentPage"] = Request.RawUrl.ToString().Replace(Request.ApplicationPath.ToString() + #"/", "");
in Main Page in page load event.
if (Session["CurrentPage"] == null)
Session["CurrentPage"] = "Exit_Tracker.aspx";
ifSideMenu.Attributes["src"] = Session["CurrentPage"].ToString();

Related

get the iframe element in C#

I'm trying to get the id of the second iframe which is iframe2 in the codebehind to add some css styling. This is my html:
<body>
<form id="Form1" method="post" runat="server">
<table id="Table1">
<tr>
<td>
<iframe id="iframe1">
</iframe>
<uc1 id="uc1"></uc1>
</td>
</tr>
<tr>
<td>
<asp:Panel id="Panel">
</asp:Panel>
<uc1 id="uc2">
</uc1>
</td>
<td>
<iframe id="iframe2">
</iframe>
</td>
</tr>
</table>
</form>
</body>
For some reason I'm not able to get the iframe id in C#. How can I do that please?
Accessing the Iframe
Ensure that you add the runat="server" attribute to the <iframe>:
<iframe id="iframe2" runat="server"></iframe>
This will enable to to access it in your code-behind via the FindControl() method:
// Access your iframe
var iframe = FindControl("iframe2");
iframe.Style.Add("border", "2px solid red");
Or directly by using its assigned id:
iframe2.Style.Add("border", "2px solid red");
Regarding Styling
You mention that you are explicitly trying to style this element. If that is the case, you should likely be using CSS as opposed to setting inline styles on the <iframe> element itself.
For instance, you could apply styles as such to target that element:
<style type='text/css'>
#iframe {
/* Place your styles here (i.e. border: 4px solid red, etc.) */
}
</style>
It's worth noting that actually styling an <iframe> is going to only style the element itself, as the content that is rendered within it is essentially "sandboxed" within the element and won't be affected by some of the assigned styles.
Change the IFrame to have runat="server" you can then get to it on the server side.
<iframe ID="MyIframe" src="" runat="server"></iframe>
You can set set items in C#.
MyIframe.Attributes["src"] = Page.ResolveClientUrl("~/ThisOtherPage.aspx");
MyIframe.Attributes.Add("style", "cursor:pointer;");

A page can only have one server-side form tag, but I need two

currently my ASP.NET web application is using a master page, nested master page and a content page. On the nested master page I have a content placeholder for navigational links, and another for the main content. The reason as to why I have two is because my main masterpage has already determined a fixed format for the rest of my pages, and I'm using nested masterpages because I need different types of navigational links for different roles used in my website. However, for the navigational links a LinkButton is used for the sign out button, thus it requires me to use a form tag with a runat="server" in order for me to be able to run the page. However, in my content page, I also need a form runat="server" tag for my main content. :-( Does anyone have an idea to propose on how to fix this problem? I want to stick to using multiple content placeholders so minor changes won't affect the entire page.
Anyways here's a snippet of my code from the masterpage
<asp:Content ID="Content1" ContentPlaceHolderID="navigationlinks" runat="server">
<form id="navForm" runat="server">
<a class="toggleMenu" href="#">
<img src="images/nav_icon.png" alt="" />
</a>
<ul class="nav" id="nav">
<li class="current">Home</li>
<li>Competition</li>
<li>Gallery</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Discussions
</a>
<ul class="dropdown-menu">
<li>Create Discussion</li>
<li>View Discussion</li>
</ul>
</li>
<li>Submission</li>
<li>Results</li>
<li>My Account</li>
<div class="clear"></div>
</ul>
<script type="text/javascript" src="js/responsive-nav.js"></script>
</form>
<asp:Content ID="Content3" ContentPlaceHolderID="Content1" runat="server">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>
</asp:Content>
ContentPlaceHolder1 is used for the main content in the content page. So even with the form tag already in "navigationallinks" I'll need another form tag
in my content page, I also need a form runat="server" tag for my main content.
You already have it since this page have a masterpage which include server-side form tag!
When you have a masterpage with
<form runat="server">...</form>
All pages using that masterpage will have the form, and no need to add it again in the page!
Edit:
Just remove all form tags inside any page or nested masterpage, and add it the masterpage wrapping all the elements.
Inside the masterpage that has the <body> tag, right after the body add the <form runat="server"> tag and close it just before the </body>. And remove all the other form tags.

Selenium webdriver c# - unable to click() element (element not null)

I seem to be having issues clicking a element inside a box which is filled by ajax.
So the web page I am on has a link on it which when clicked this calls a javascript function which then inserts a new div into the page which is full of new content.
Now the weird thing is I can find the element inside this box no problem using xpath, and I can even read its value but! I can't use Click(); on the link inside the box the event just wont work for some reason.
Has anyone faced a similar issue and know a work around?
I am using Selenium webdriver 2.35 with Firefox 23
More Info
OK so the HTML for the link I click which calls the JS to make the div appear.
<center>
<a id="link_fleet_move_here" href="">Move fleet here</a>
</center>
<br>
<script>
$("#link_fleet_move_here").click( function(event) { event.preventDefault(); load_fleet_move_to_destination("fleet.aspx?method=ajax&view=move_to_destination&version=1&player=111&destination=LZLOCATION"); $("#link_fleet_move_here").hide();} )
</script>
<center>
<div id="fleetLoaderTemplate" style="display:none">
<div id="fleetLoaderErrorTemplate" style="display:none">
</center>
<div id="move_to_destination_container"></div>
And when the event finishes loading the new HTML
<div id="move_to_destination_container">
<ajax>
<table width="600" align="center">
BIG TABLE FULL OF CONTENT
<td sorttable_customkey="LZLOCATION">
(LZLOCATION)
</td>
<td sorttable_customkey=""></td>
<td sorttable_customkey=""></td>
<td>
Move
</td>
<table>
<br>
</ajax>
</div>
The Selector
location = driver.FindElement(By.XPath("//a[contains(#href, '" + LZLocation + "')]/following::td[3]"));
location.Click();
I think it may be something to do with that div actually, I think it starts as Display:None and gets changed, this will be effecting it?
I thought it was dynamically adding it but maybe not!
Try selecting your element via the following:
driver.findElement(By.cssSelector("#move_to_destination_container a[href^='fleet']")).click();
If it throws an error, try using:
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#move_to_destination_container a[href^='fleet']"))).click();

Positioning the starting position of Horizontal Scrollbar slider on the right

I want to Set the Horizontal Scrollbar slider to the right without using css direction:"ltr" or dir="ltr" or an asp:Panel direction="rightToLeft"....
i just want to access the object that controls the Horizontal scrollbar slider to give it the position.
from aspx page or the aspx.cs.
aspx page :
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../js/BeginScrollFromRight.js"></script> . . .
<body id="body" style="overflow:auto; height:100%;width:100%;"> . . . </body>
js page :
function BeginScrollFromRight()
{
$("#body").scrollLeft($(window).width());
}
I need to have the same effect for the direction:rtl but only for the horizontal scrollbar because other object are not supported when using direction:rtl
<td id="tdView" runat="server" dir="ltr" align="center">
<table onclick="hideMenusComplex();" oncontextmenu="hideMenusComplex();" id="tblView" runat="server">
<tr>
<td>
<asp:Label ID="lblView" runat="server" ForeColor="#5E82D6" Visible="false"><%= translate("View : ") %></asp:Label>
</td>
<td>
</td>
<td>
<cc1:Combobox AlignContainer="Center" ID="ddlViews" runat="server" OnClientChange="onChangeValue()"
FolderStyle="../EsStyles/ComboXpBlue" AutoPostbackEnable="false" Width ="200">
</cc1:Combobox>
</td>
<td>
<asp:Label ID="lblViewArabic" runat="server" ForeColor="#5E82D6" Visible="false"><%= translate("View : ") %></asp:Label>
</td>
</tr>
</table>
</td>
This is the code and the ddlViews is the dropdown list that is opening in a wrong way, the dropdown list is not opening under the control is opening on the left of the control.
For languages the read right-to-left, direction: rtl is really the only way that will work well, in the end.
If you just want to scroll all the way to the right, jQuery JavaScript like:
$("#YourContentDiv").scrollLeft($("#YourContentDiv").width());
or:
$(window).scrollLeft($(window).width());
will do it.
.
In case you are new to jQuery, you can add it to your page, like this.:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function jQueryMain ()
{
$("#YourContentDiv").scrollLeft($("#YourContentDiv").width());
$(window).scrollLeft($(window).width());
}
$(document).ready (jQueryMain);
</script>
.
PS: jQuery takes most of the cross-browser hassle out of JavaScript like this.

xVal and jQuery Submit Button

I have a simple form. Its got one field and a submit button.
I hide the submit button. The submit button is actually triggered with an anchor
tag that calls a javascript method that uses jQuery to get the element and execute
a click(). This works fine, the form posts and record is successfully written into the DB.
So now I added xVal for validation. I am trying to add in the simple client side validation.
It doesn't work when I click the anchor tag. However, if I un-hide the submit button and try posting the form with that instead of using the anchor tag that's calls the js method, it does work. So basically I am trying to figure out why it doesn't work when I use the js method to trigger the click of the submit button.
Any grande ideas? Thanks much!
Heres some code...
<div id="manufacturerButtons" class="moduleRow">
<%= Html.ActionImage(Url.Content("~/Content/Icons/bullet_go_back.png"), "Back To Admin", "Admin", "Admin")%>
| <a class="actionImage" href="javascript: addManufacturer();">
<img border="0" src="<%= Url.Content("~/Content/Icons/accept.png")%>"> <span>Add
Manufacturer </span></a>
</div>
<div class="moduleContent">
<div id="manufacturerContainer">
<div class="moduleRow">
<h3>
New Manufacturer</h3>
</div>
<div class="moduleRow">
<% Html.BeginForm("NewManufacturer", "Admin", FormMethod.Post); %>
<table class="noBorder" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 125px">
<h6>Name:</h6>
</td>
<td>
<%= Html.TextBox("Name") %>
</td>
</tr>
<tr style="display: none;">
<td>
</td>
<td>
<input type="submit" id="btnAdd" name="btnAdd" />
</td>
</tr>
</table>
<% Html.EndForm(); %>
<%= Html.ClientSideValidation<EquipmentManufacturer>() %>
</div>
</div>
Javascript:
function addManufacturer() {
//$('form').submit(); // doesnt work when trying to validate either
$('#btnAdd').click();
return true;
}
What you need to do is trigger the jQuery validation on your form. Try:
$('form').validate();
To submit the form upon successful validation, try:
$('form').validate({ submitHandler: function(form) { form.submit(); } });
Note that 'form' should be a valid jQuery selector for your form...

Categories

Resources