here at home I have different projects and libraries for which I've created an helpfile with Sandcastle.
Now Sandcastle provides also the possibility to create a website.
What I would like to do is to create an aspx-page where I can dynamically create a menu and where the existing helpfile-websites can be sollicited. All in one place.
Is it possible to accomplish this? Maybe some control that I can use to view an entire webpage?
Thank you.
EDIT:
Seems I can't get it to work in an ASP-page for whatever reason, but probably because of the way Sandcastle creates the help-pages.
I've now tried it with a WinForm-application with a webbrowser-control and this approach works, so I guess this will be the way I have to go here.
But I do need to say thanks to Alison (and Leon) for their help regarding this issue.
Their solution works for "normal" html-pages, but (unfortunately) not for the ones I have.
For that reason, I've accepted the answer so others could benefit from it.
Updated
Take a look at jQuery load. You can have a div on your page and load the html from an external page into it. The load function can grab individual pieces of HTML from a different page.
On your main page, add this html:
<div id="myexternalpage"></div>
On the different page, add a div tag with an id around the content you want to grab like:
<div id="myexternalcontent">Test</div>
The add the following to your head tag:
<script type="text/javascript">
$(document).ready(function() {
$('#myexternalpage').load('myexternalpage.html #content');
})
</script>
Notice the addition of the "#content" selector to the end of the load function? This will have jQuery load the different page and return only the content in the div with id="content".
Using jQuery load will let you load the content once the page loads and you won't need to use any iFrames. You can use CSS to handle the height/width and handle any overflow.
I've made a quick and dirty test-page:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Test2.aspx.cs" Inherits="Test2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js " ></script>
<script type="text/javascript">
$(document).ready(function () { $('#myexternalpage').load('WebHelp/KoenHoefman/ExhangeRateWebService/Index.html'); })
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="myexternalpage">
</div>
</form>
</body>
</html>
But I get an error on the script line.
Microsoft JScript runtime error: Object expected
Do I have to replace document with something (probably a stupid question but I'm not used to use javascript)?
Update:
Added Leon's code and now it shows something. But when I want to use the page I really want to show (which is located in a subfolder) I get only the items on the index.html. The page that should be loaded into the IFrame of that page isn't shown. Also the pictures that are located in the same folder are not shown.
Error: HTTP 404
Requested URL:
/html/aea04102-3d0d-cf0d-f5f4-5634f5f06aed.htm
Related
I am working on automating an area of a web page (not able to provide the webpage as the contents are confidential, although will try to give as much insight as possible).
This element has on it an html code preview that will change after some selections are done. Here is the page html of the element:
<div _ngcontent-hje-c241="" class="field" style="position: relative;">
<pre _ngcontent-hje-c241="" class="code-pre">
"
<!doctype html>
<html>
<head>
<meta charset='utf'>
<title></title>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<style type='text/css'>body,html, #video {height:100%;margin:0;overflow:hidden;background-color:#000;}</style>
<script type='text/javascript'>
window.onload = function(event) {
var config = {containerID: 'video', Player: true, wmode: 'direct'};
myplayer = new Test.embed('WmAl', config);
}
</script>
</head>
<body>
<div id='video'></div>
</body>
</html>"
(I have edited and removed any confidentials parts of the string for the html, the html itself was not changed.)
I would need to get the value of the element I found through class="code-pre".
Here is what I have tried:
IWebElement htmlTest = driver.FindElement(By.ClassName("code-pre"));
var defaultHtmlTestValue = htmlTest.GetAttribute("value");
Assert.IsFalse(htmlTest.Equals(defaultHtmlTestValue), "The html has not changed after the Http selection");
The assert passes, altho, i would like to see what is the value that is being taken, as i feel like is not taking the html example i am trying to get.
I have also used Debug.Writeline(htmlTest) to see if it worked, but i got "Internal error in the expression evaluator". This is also an issue i will be trying to fix.
I am quite new to automation and stack overflow. Please let me know if there is a way i can improve this post.
I haven't worked with the html previews but looks like the whole html code is just the inner text of an element with class code-pre.
try doing :
String htmlTest = driver.FindElement(By.ClassName("code-pre")).getTex();
System.out.println(htmlTest);
Assert.assertTrue(htmlTest.Equals(defaultHtmlTestValue), "The html has not changed after the Http selection");
You can easily convert above java code into your language.
I'm reading in an .ASP page from a server. The problem I am having is that the page is becoming truncated when I attempted to read the data in by means of the C# code below.
Below is my code accessing the .asp page
var htmlDocument = EmbeddedBrowser.Document as IHTMLDocument2;
var htmlInnerContent = (((HTMLDocument)(htmlDocument)).documentElement).innerHTML;
Below is the .asp page as it sits on my server
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><script type="text/javascript">Lots of Java Script Here</script><script type="text/javascript">Lots more Java Script Here</script>
</head>
<body>
<input type="" name="ExpectedClientVersion" value="20.15.09"/>
</body>
</html>
Below is the content of htmlInnerContent after I read it in
<head>
<script type="text/javascript">Lots of Java Script Here</script
</head>
As you can see I am missing the body which is really what I need so I can parse the ExpectedClientVersion.
I have run a fiddler trace and I can see the entire document being passed over.
I also tried researching limitations of .InnerHTML but found only lacking documentation. There may be something to this.
I feel the way I am accessing the document may be incorrect. Does anyone have insight into this?
I need some help figuring out the best way to go about adding jquery code to my aspx file. We have a big front end solution in VS2008 using a master page. In the master page we have a ContentPlaceHolder where you can add stuff to the <head>, but the location of the place holder is above the code which declares the local path to jquery. Would I need to move the ContentPlaceHolder to a location below the jquery? If so, couldn't doing that cause some potential issues? I tried adding an additional ContentPlaceHolder under the script declaration tags, but that caused ViewState errors (I think having to do with code behind I added for my page to allow CSS3 for IE).
Here is the relevant code from the master file:
<%# Master Language="C#" AutoEventWireup="True" CodeBehind="Class.Master.cs" Inherits="Company.Project.Masters.Class" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title><%# Page.Title %></title>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<asp:ContentPlaceHolder ID="cphHead" runat="server" >
</asp:ContentPlaceHolder>
<link href="~/inc/style.css" rel="stylesheet" type="text/css" />
<script src='<%# ResolveUrl("~/inc/utils.js") %>' type="text/javascript"></script>
<script type="text/javascript">
//some js stuff here
<style type="text/css">
// some css stuff here
</style>
<script language="javascript" type="text/javascript" src='local/path/to/jquery' ></script>
<script language="javascript" type="text/javascript" src='local/path/to/jquery-ui-1.10.3.custom.min.js") %>'></script>
<script type="text/javascript">
$(document).ready(function() {
//some jquery stuff here
})
});
</script>
</head>
Below is the code I have added to my page's .cs file to allow CSS3 elements to work in IE. This error looks like it is related to the ViewState error
protected void Page_Load(object sender, EventArgs e)
{
HtmlMeta xuac = new HtmlMeta();
xuac.HttpEquiv = "X-UA-Compatible";
xuac.Content = "IE=edge";
Header.Controls.AddAt(0, xuac);
}
When I add a new ContentPlaceHolder in the MasterPage I get the error:
Failed to load viewstate. The control tree into which viewstate is
being loaded must match the control tree that was used to save
viewstate during the previous request. For example, when adding
controls dynamically, the controls added during a post-back must match
the type and position of the controls added during the initial
request.
Coming to all your points one by one.
You can have multiple content place holders in master page and you can refer to them in other pages. You should add a contentplaceholder right after jQuery script. And add content to this placeholder from child pages, it should not create any kind of problem.
Please share the view-state error you are getting on adding extra contentplaceholder. You can explore browser console for more information on view state problems.
I am building a website which allows people to send out emails to people with a choice of different templates. When they have set-up their email and chosen a template the user can preview it. At present this loads up the corresponding aspx page to the template selected.
I currently have 3 templates but expect this to grow substantially.
The aspx pages all have the same controls, with the same names and even the codebehind(cs) page is the same. So it would be far simpler and efficient if i could somehow tie this pages together and minimise repetition, perhaps even just using one page but loading up the HTML corresponding to the selected template.
I cant think of an appropriate way to do this, or even work out if its possible. Ive probably got to the point where i cant think straight on the matter since its giving me such a headache.
So.....
Please please please give me some solutions or even just suggestions. ;-)
Thanks.
ADDITIONAL INFO
As an additional problem, i have to recreate the templates programatically when the emails are created and sent out to recipients as HTML emails. This is done via a different page and thus results in more duplication that id like to minimise.
create a Page class, let say, TemplateViewerPage
TemplateViewerPage.cs
using System;
using System.Web.UI;
public partial class TemplateViewerPage : Page
{
protected override void OnLoad(EventArgs e)
{
// load your properties
_subject = "test";
_messageBody = "body";
base.OnLoad(e);
}
// your property
private string _subject;
public string Subject
{
get { return _subject; }
set { _subject = value; }
}
private string _messageBody;
public string MessageBody
{
get { return _messageBody; }
set { _messageBody = value; }
}
}
then you can create viewer for template A :
ViewerA.aspx
<%# Page Language="C#" AutoEventWireup="false" Inherits="TemplateViewerPage" CodeFile="TemplateViewerPage.cs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Subject</td>
<td> <%= Subject %> </td>
</tr>
<tr>
<td>Message</td>
<td> <%= MessageBody %> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
and ViewerB, with same code behind (codefile=TemplateViewerPage.cs)
ViewerB.aspx:
<%# Page Language="C#" AutoEventWireup="false" Inherits="TemplateViewerPage" CodeFile="TemplateViewerPage.cs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="subject">
<%= Subject %>
</div>
<div class="message">
<%= MessageBody %> </td>
</div>
</div>
</form>
</body>
</html>
How about MasterPages for the templates? The select the appropriate master page at PageLoad.
If it's content then using CSS for the formatting (you can obviously change the CSS being loaded at Pageload) also Placeholders and populating them from your data store for the mails is another option.
It think there are probably as many solutions as there are users on StackOverflow ;)
If all the controls and code behind are the same, couldn't you put all the controls into a masterpage and simply use content pages for the actual emails?
Ah I see. Although it changes is it always in a similar structure? Because you can have multiple content holders in a masterpage. So in the masterpage you would be able to have content wrapped around the controls as follows:
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:Button ID="button1" runat="server" />
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
I haven't found that the asp.net web forms page, master pages, or mvc is a very good fit for this sort of thing. It's like using a sledgehammer to crack open a peanut.
It's very straightforward to create some custom xml tags and then merge them yourself. Save the template in the database and merge whenever you like, and without all the overhead of running asp.net. Use agile principles: create your tests first and work backwards and you'll have exactly what you need running in no time.
The most basic is straight string replacement. If you need more, which it doesn't sound like you do, you could use xslt or just walk the DOM (ie store your templates as xhtml and have your own custom tag support).
There's also an issue of deployment. It's a lot easier to update templates in a database than it is to upload files to a server. If you do go down the route of using web forms, make sure you understand the deployment scenario's before you .
Warning: html emails are tricky, and there's a lot of ugliness (from an html standpoint) to get them to render uniformly in email clients. Expect to code the html like it's 1999, and that's pretty much the state of html emails. Sad but true.
I'm attempting to create a custom calendar control that inherits from ASP.Net's built in calendar user control.
the code-behind file for my control looks like this:
public partial class WeeklyEventsCalendar : Calendar
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
and compiles fine.
However, when I try to place my custom control on an aspx page:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="testbed.aspx.cs" Inherits="testbed" %>
<%# Register Src="UserControls/WeeklyEventsCalendar.ascx" TagName="WeeklyEventsCalendar"
TagPrefix="mvs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<link href="~/css/VitalSignsStyleSheet.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div>
<mvs:WeeklyEventsCalendar runat="server" />
</div>
</body>
</html>
I get a warning 'Element WeeklyEventsCalendar is not a known element. This can occur if there is a compilation error in the web site, or the web.config file is missing.' Attempting
I don't get any sort of 'file not found' error like I have in the past when I mis-typed the location of the file.
When I attempt to load aspx page in a browser, I get error CS0115: 'ASP.usercontrols_weeklyeventscalendar_ascx.FrameworkInitialize()': no suitable method found to override
Which is even more confusing, because nowhere in my code do I attempt to define such a function.
This should be really simple. Where am I going wrong?
I think the problem is that you're attempting to inherit the Calendar control (which is a server control) from a user control (based on your ASCX extension). You can't do this. If you want to inherit from the Calendar control then you need to create a server control.
Let me know if you need some sample code.
Bryant hit on it. One thing you might consider if all you're doing is customizing the existing control is embedding an instance of the calendar on your user control and exposing the properties you need from it. This way your user control can handle all of the requisite customizations, and also provide only a limited interface back out to the consuming application. (This is composition instead of inheritance.)
If you really do need to fully derive from asp:Calendar, then you need to create a standard class which derives from the Calendar control, and then perform your customizations. You'll have no UI design for that, however -- everything you do will need to be custom code. (And if you need to change the HTML being emitted, you'll need to write those custom streams out as well -- which, with a calendar control, could be painful.)