Is there a way to render Partial Views in WebForms? - asp.net-3.5

I'm touching an old WebForms project but I'm long gone from it and I'm now to used to MVC. I'm trying to refractor the project and come up with a simple issue that is making me crazy...
What would be the best way to include an .aspx file within another?
I don't want to end up having a lot of Master Files just for this, all I'm after is something like #Html.RenderPartial("MyFileName") kind'a thingy or
it's that hard to include a file in some existing files?

Use UserControl Tutorial on UserControl. They are files with .ascx extension and you can include them in your pages
//UserControl1.ascx
<% # Control Language="C#" ClassName="UserControl1" %>
<div>
My Custom Control: I can use any Server controls, html tags etc
</div>
Include it in your .aspx page
<%# Page Language="C#" %>
<%# Register TagPrefix="uc" TagName="MyCustomControl" Src="~/Controls/UserControl1.ascx" %>
<html>
<body>
<form runat="server">
<uc:MyCustomControl id="MyPartialView"
runat="server" />
</form>
</body>

Related

Template overlay using Sightly

I am pretty new to AEM. I am following this tutorial from the official documentation. I already did it from top to bottom, but now I am trying to do it again but using Eclipse, Maven and Sightly instead of JSP.
I've been following until the step "Using your own scripts". As I am trying to use Sightly instead of JSP I've ended up with the following files:
contentpage.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<div data-sly-include="head.jsp" data-sly-unwrap></div>
<div data-sly-include="body.jsp" data-sly-unwrap></div>
</html>
body.jsp
<%#include file="/libs/foundation/global.jsp"%>
<%
%><body>
<div id="CQ">
<div class="topnav">topnav</div>
<div class="content">
<cq:include script="left.html" />
<cq:include script="center.html" />
<cq:include script="right.html" />
</div>
<div class="footer">
<div class="toolbar">toolbar</div>
</div>
</div>
</body>
left.html
<div class="left">
<div>logo</div>
<div>newslist</div>
<div>search</div>
</div>
center.html
<div class="center">
<div>trail</div>
<div>title</div>
<div>parsys</div>
</div>
right.html
<div class="right">
<div>iparsys</div>
</div>
In addition, the node apps/myproject/components/contentpage has an attribute sling:resourceSuperType="foundation/components/page" so it is inheriting from the page component provided.
Everything works as expected, but as I said before, I am trying to use only Sightly, but at the moment I've got the file body.jsp, which I think I need it to be JSP so it has the same name as /libs/foundation/components/page/body.jsp.
Is there a way to get rid of the body.jsp and use a sightly script instead? I suspect that maybe there is a components/page/body.html somewhere, but no idea where to look for it (in case it really exists).
Thanks.
As commented by rakhi4110, and as I suspected, there is a sightly version of the page component. It is located in wcm/foundation/components/page so the only thing to do is inherit from it instead of foundation/components/page.
This is a link to an article that put me on track, in case is useful for somebody else: http://scottwestover.blogspot.co.uk/2015/04/aem-tutorial-on-building-sightly-page.html

stylesheet_link_tag returns <base href="/"> instead of <link>

Bundler update for the entire application caused a very specific issue with the <link> being returned from <%= stylesheet_link_tag 'application', media: 'all'%>
Instead of returning the usual <link rel="stylesheet" href="assets/application.css"> , it now returns <base href="/">
If I edit the HTML to manually add the <link>, the css shows up correctly which indicates that there is no compiler issue. Also, some answers that fixed somewhat similar problems did not work with this specific issue including (but not limited) to the following solutions:
# Enable the asset pipeline
config.assets.enabled = true
# Fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# Serve Static Assets.
config.serve_static_files = true
Also, switching ENVs and clearing cache with rake tmp:cache:clear and rake assets:clean did not had any effect on the issue...
To make things weirder, the ember stylesheet and script are working as expected:
<%= include_ember_stylesheet_tags :frontend %>
<%= include_ember_script_tags :frontend %>
<link rel="stylesheet" href="assets/frontend.css">
<script src="assets/frontend.js"></script>
Issue is possibly related to one of this gems:
Rails (4.2.5)
Sprockets (3.5.2)
You can view the complete Gemfile.lock or the entire Source Code on Github.
Another possible root cause is a new route configuration where somehow mount_ember_app :frontend, to: "/" relates to the lack of <link> being returned and <base href="/"> being returned instead since both maps to "/". However, I could certainly be wrong about it...
This is all the information that I was able to gather since I could not see any useful information on the logs including the browser's output.
This problem showed up after several upgrades around, especially after mount_ember_app was created. The way to fix it is to have a similar structure to the following:
Ember-Cli-Rails Initializer
EmberCLI.configure do |config|
config.app :frontend, build_timeout: 30
end
Routes.rb
mount_ember_app :frontend, to: "/", controller: "application"
App/views/application/index.html.erb
<%= render_ember_app :frontend do |head| %>
<% head.append do %>
<%# Rails Asset Pipeline%>
<%= stylesheet_link_tag 'application', media: 'all'%>
<%= javascript_include_tag 'application' %>
<%# Ember-cli-rails Pipeline - Frontend Stylesheet is not used.%>
<%= include_ember_script_tags :frontend %>
<% include_ember_stylesheet_tags :frontend %>
<%# META Stuff %>
<%= csrf_meta_tag %>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<% end %>
<% end %>
Frontend/App/index.html
<!DOCTYPE html>
<html>
<head>
<title>Frontend</title>
{{content-for 'head'}}
{{content-for 'head-footer'}}
</head>
<body>
{{content-for 'body'}}
{{content-for 'body-footer'}}
<%= render partial: "layouts/shared/analytics" %>
</body>
</html>
This will solve most, if not all assets issues. <base href="/"> apparently is normal as I now believe that it simply refers to the mount point for the Frontend.
I also had issues with #mixins after most of the SCSS came back to life, but later I found out that they were tied to a totally different issue, and therefore will not be discussed in this answer.

MaskEditExtender Ajax toolkit- not able to copy paste IE 11

I have two date textboxes in my ASP.Net application and these textboxes are using MaskEditExtender so that only date can be entered in them. These textboxes are actually from and to textboxes to enter a date range.
The issue is that in IE 11 the user is not able to copy-paste date from one text box to other using Ctrl+C and Ctrl+V.
The user is able to paste the date by right clicking and selecting copy paste but in this also the date does not get properly formatted in the second textbox. In IE8 and lower browsers it worked fine.
Sample code used:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox1"
Mask="99/99/9999" MaskType="Date" ClipboardEnabled="true"/>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender2" runat="server" TargetControlID="TextBox2"
Mask="99/99/9999" MaskType="Date" ClipboardEnabled="true"/>
</div>
</form>
</body>
</html>
Please suggest.
Yes, there is a bug that was fixed recently, but this fix is not published at the moment.
You can see changes here or wait for new ACT release.

Web pages accessible by multiple URLs for SEO reasons

I have a bunch of pages with the following structure:
<html>
<body>
<div id="summary">
</div>
<div id="promotions">
</div>
</body>
</html>
I want these pages to be accessible by both:
/items/one
/items/two
/items/three
And:
/promotional-offers/2014/february/one
/promotional-offers/2014/february/two
/promotional-offers/2014/february/three
/items/... should just open the page. /promotional-offers/2014/february/... should open the page /items/... and go to the anchor #promotions (scroll down to the appropriate div).
/items/one/#promotions
/items/two/#promotions
/items/three/#promotions
I'm not sure though how to set up rewrite rules in web.config to help search engines with indexing my pages and avoid having 'duplicate content'.
I would add a Canonical tag to completely avoid duplicate content, so It won't matter from which page you are showing the same content.
<!--url /promotional-offers/2014/february/one-->
<link rel="canonical" href="http://www.example.com/items/one" />

Can Ant be used to embed variable AngularJS templates?

I want to embed a variable amount of text files (AngularJs templates) at a specific point of a given text file (./WEB-INF/app.html) but except modifying the file saving it as another file (./index.html?.
The files I want to embed all have file names ending with *.ng.html and are all in a subfolder of ./assets/templates/.
Also I want to write text before and after the embed file (To make AngularJS recognise that they are templates). This text should consist of both static text and the file names relative to the working directory.
This is a possible structure of a working directory:
(index.html) (generated after building)
--assets
--templates
--general
about.ng.html
contact.ng.html
home.ng.html
--users
userlist.ng.html
--WEB-INF
app.html
Can this be done using Ant? If not, how could I do this at build-time in Eclipse?
To further illustrate my intentions, here are examples:
./WEB-INF/app.html
<!doctype html>
<html><head>
#INSERTION_POINT#
</head><body></body></html>
./assets/templates/general/about.ng.html
This is a test.
./assets/templates/general/contact.ng.html
You can contact me at: <a href=mailto:mail#example.com>mail#example.com</a>
./assets/templates/general/home.ng.html
Welcome.<br>
Click a link to explore.
./assets/templates/users/userlist.ng.html
<ol>
<%= "{{#userlist}}" %>
<li>
{{username}}
</li> <%= "{{/userlist}}" %>
</ol>
After building, I want ./index.html to look like:
<!doctype html>
<html><head>
<script type="text/ng-template" id="/assets/templates/general/about.ng.html">
This is a test.
</script>
<script type="text/ng-template" id="/assets/templates/general/contact.ng.html">
You can contact me at: <a href=mailto:mail#example.com>mail#example.com</a>
</script>
<script type="text/ng-template" id="/assets/templates/general/home.ng.html">
Welcome.<br>
Click a link to explore.
</script>
<script type="text/ng-template" id="/assets/templates/users/userlist.ng.html">
<ol>
<%= "{{#userlist}}" %>
<li>
{{username}}
</li> <%= "{{/userlist}}" %>
</ol>
</script>
</head><body></body></html>
I figured out that I can get a list of the files I want to embed using:
<fileset dir="war/assets/templates">
<include name="**/*.ng.html"/>
</fileset>
When I have the final string, I could replace my placeholder and save the output to a new file probably like this:
<copy file="WEB-INF/app.html" tofile="index.html">
<filterset>
<filter token="INSERTION_POINT" value="??foo??"/>
</filterset>
</copy>
But how do I get the string I want to have to pass as a value?
definitely not what you're looking for... sorry... but might look into a Javascript oriented build tool (Grunt) and integrate that with eclipse (or even run it from ant if you're trying to keep your builds the same in java and javascript.)
Though this may not be exactly what you're looking for, you're guaranteed lots of community support if you stick to the standards.