Replace / Change .aspx page at runtime - asp.net

I use DNN with AngularJS and bootstrap. Now I have a page layout in the form of
What I want now is, according to a function of what the user selects in the menu must master and detail to be replaced.
There are different .aspx pages that I would have to add at runtime.
Is there an easy way?

You cannot "replace" the .ASPX page - you can request HTML from different endpoints (pages, if you will) and ASP.NET would generate them based on the request.
That linguistic inaccuracy aside, you'd need to have your client Angular app render different templates based on some selection value. You can use ng-include and link to a template URL, which could be generated by your .ASPX page.
So, imagine you have a simple HTML page like this:
<select ng-model="selection" ng-change="changeMasterAndDetail()">
<option value="foo">foo</option>
<option value="bar">bar</option>
</select>
<div ng-include="master"></div>
<div ng-include="detail"></div>
In the controller, you can assign the template Url depending on the selection:
.controller("SelectionCtrl", function($scope){
$scope.selection = foo;
$scope.changeMasterAndDetail = changeMasterAndDetail;
changeMasterAndDetail();
function changeMasterAndDetail(){
if ($scope.selection === "foo"){
$scope.master = "/path/to/master/pageA.aspx";
$scope.detail = "/path/to/detail/pageA.aspx";
} else if ($scope.selection === "bar"){
$scope.master = "/path/to/master/pageB.aspx";
$scope.detail = "/path/to/detail/pageB.aspx";
}
}
});

If you are asking to replace the content of details on the basis of the click of the menu items in the master section , you only need to put a Option .
You can create a master page where you keep the master section and all your tabs or options in them along with the href having the URL of your content page.
You should also add a <ContentPlaceHolder> in your master page where in the content of the details page will go.
Now, when you create a new page , you choose the master page and simply start writing content in the <asp:Content> area. By this all your content will appear in the details area. And that area will be loaded dynamically based on the href .

Related

How to manage a list elements staying on the same page

By default, rails has controller CRUD actions with corresponding routes. For instance, I have a simple bookstore app, where I have a book and category. I want to display all categories through a sidebar on a home page. Each category is a dropdown element accompanied with a books count integer. When expanding a dropdown I want to see a book title that belongs to a current and acts as link. That is easy to implement.
The question is how can I add a form hidden under, let's say a + sign, sticked next to a static Dropdown section title "Categories" if there are none?
A form for Create action in Category controller which would allow to create a new category and display it straight away without redirecting to Create category view and redirecting back.
Please advise any reliable solution or tutorial link. Thanks a lot.
It looks like you are looking for an AJAX form. In rails you can generate this with form_for ... remote:true. This can call a controller method with out refreshing the page. You can then return a response and use JS to update the page the user is on.
For example, in your view
<div class="hidden">
<%= from_for #category, remote:true %>
Your form here
<% end %>
</div>
Add in some JavaScript to un-hide the form when your button is clicked. In your controller
def create
#normal create stuff
if save
respond_to do |f|
f.js
f.html {#re render page just in case JavaScript is disabled}
end
else
#handle error
end
end
using the rails default f.js, Rails will call a file create.js.erb this file will have access to any public variable you make, for instance #category.
you can then do somthing along the lines of
$('.append_category').append('<%= j render 'your category layout partial', locals: { category: #category }%>');
or if you just need the category link
$('.append_category').append('<%= link_to #category %>');
A very nice guide can be found here http://guides.rubyonrails.org/working_with_javascript_in_rails.html
Note: depending on your version of rails, you may need to add include ActionController::MimeResponds to your application_controller.rb (I know this is required in rails 5)

view sections cause problems if not rendered in layout

I'm converting an MVC aspx content place holder -> master page to an MVC razor section -> layout.
In the past when my aspx view came to something like this:
<asp:Content ID="HelpContent" ContentPlaceHolderID="HelpLink" runat="server">
Help
</asp:Content>
And the master page didn't have a corresponding HelpContent place holder (perhaps because a user was not authenticated) everything rendered fine (with no HelpContent section).
Now when I have a razor section defined that does not have a corresponding #RenderSection in the layout, I get this error:
The following sections have been defined but have not been rendered
for the layout page "~/Views/Shared/New.cshtml": "HelpLink".
Do I need to redesign this?
Is there a way I can have the view's HelpLink section render optionally if the layout gives it the green light?
EDIT:
I think there's some confusion, so let me re-summarize:
The layout logic looks like this:
if (User.IsLoggedIn) {
#RenderSection( "HelpLinks", false);
}
But then the user isn't logged in, it doesn't render, and then .NET throws an exception because the layout doesn't know what to do with the section.
You can indicate that the section is optional by passing false as the second argument:
#RenderSection("HelpLink", false);
Edit: In the case of control flow logic for rendering, you can use .NET in the razor view (like this c# example):
#if(IsSectionDefined("HelpLink"))
{
#RenderSection("HelpLink", false);
}
Or, if you want to base rendering on whether the user is logged in, you could replace the if logic in the above sample with your security check.
Edit 2:
Make sure you have defined the section:
#section HelpLink {
//This needs to be defined in any view that uses the layout with the #RenderSection. It can be empty.
}
Alternatively, you can add the check to see if the section exists and only define the #section in the required view:
if (IsSectionDefined("HelpLink") && User.IsLoggedIn) {
#RenderSection( "HelpLinks", false);
}
If a section is declared in a razor view it has to be rendered in the layout.
I found this in Freeman's Pro ASP.NET MVC 5 book.
Seems like a bad design to me.

Drupal: views display as a block; putting inside an html tab

Drupal 6.28:
I'm re-theming a particular section of a site and the new design called for five pages to be displayed as five tabs on one page with the appropriate one shown when either clicking on the tab itself or in an expanded menu to the left.
I created all that in html and jquery so that I could deep-link the tabs, ie... someone can click on any menu link and hit the page with the appropriate tab open instead of having to go to the master page and then click the appropriate tab. (using location.hash)
This is all working fine, but the last tab is to house content that currently is a view set as a block.
What is the best way to pull that view/block into the html div I have set aside for that specific content?
I have used this great snippet before:
<?php
$block = module_invoke('block', 'block', 'view', '15');
print $block['content'];
?>
which allows one to place any block anywhere, but with a view with a display set as a block, I'm not having any luck invoking that view. Also, I'd had to have to use "php" instead of 'full html' on the node since it's just a snippet but as it's not currently working, it probably doesn't matter.
so, I'm trying to figure out how to have something like this:
<!-- all the other tabs content-->
<div id="fifthTab">
all the content from the view which is set to 'display like a block'
</div>
I'm fairly new to Drupal and not even sure if I create a page display how I would call that data anyway.
So my html structure is:
MAIN PAGE LINK
-sub link/tab 1/default
-sub link/tab 2
-sub link/tab3
-sub link/tab4
-sub link/tab5
So if someone either clicks on on the sub link/tab 5 in the left nav or clicks on the actual tab 5 or enters the url xxx/#tab5, the appropriate tab is show, the rest hidden. That's all working great, I just cant get the view content to show in that tab5.
so a page template based on the url is the easiest. The variable $content is just placed in the last tab and all other html content for that specific page is just put in the template.
At least this way, as docs are added, it's still dynamic and the static info is easy to edit if needed.
Just in case something similar comes up for someone else.

Can't render an action in base layout and execute it from child template

Am working on a Symfony2 application whose among its functions will allow the user to select to visit different sections of the site, and this from anywhere (any page) of the site. For simplifying let's say: when a user want to sort he/she choose from a drop down select form and submit.
I built the action and template with a test root to verify this function and this work (when I use directly the rendering of that sortAction() on my app_dev/test adress.
The issu is that when I try to make this action accessible from the general template (app/Resources/views/base.html) I can view the select form with default view, but when I select for a sort and try to Submit page relaods and return to the defaut view.
I use {% render "MycompanyMybundleBundle:Mycontroller:sort" %} in .../base.html and I want this action to work on (like) mysite/anypage this last extending bundle layout which (layout also extent base).
Can anyone help me?
The description of your problem isn't realy clear, but I think the problem lies at the form action. Do you've configured this action? You should leave it empty if you want to submit it to the same page.
Another solution would be to make use of the extending posibilities of Twig. Define the form as a block in the parent, and override it in the child.
http://twig.sensiolabs.org/doc/tags/extends.html
EDIT:
You could make the form action a block, that is what I mean...
<form action="{% block formAction %}defaulttargetpage.php{ %endblock% }"> <!-- formcontent --> </form>

How to set the number of item per page in a Drupal View?

I have a problem at which I have a view that will display a featured item and 6 rows on the first page of the view, while displaying 9 rows on the rest of the pages. Is such a functionality possible with views?
Thanks!
A few methods I can think of. I have mentioned them on the basis of how long it will take you.
1) Create a custom css rule which hides two entries on the first page. As for the rest of the pages you can show it.
2) Find the template file of your particular views and then use php to hide those rows. You can find the name of this file in your views theme section.
3) You could write a php module which can do the same as views. Its not that hard to get it done.
UPDATE
Below is the jquery which will help you get the logic right
$(document).ready(function() {
var pathname = window.location.pathname;
// here we assignt he current url of the page to the var pathname
});
if(pathname =='firstPageofView')
{
// if the path name is the first page of the view then we assign special css formating
$('#divid').hide();
}
else
{
$('#divid').css('width','10px');
}
Cheers,
Vishal

Resources