Inject Code Into Masterpage / Html Head From A User Control?
Jan 10, 2010
I am struggling with something that I guess should be standard practice really. I have a number of user controls that use some JQuery plugins. I do not really want to link to the extra CSS and JS files from my main masterpage as this would cause extra load to the user the first time they hit the site, (admittedly it would only be the once), so I was just putting them links into the top of the user control. Then I looked at my source HTML, not nice! Even worse for controls that repeat multiple times on a page.
So I was thinking is there a way of injecting them into the Head of the page when they are needed from the User Control. For that matter is there a way of doing it to the footer for JS stuff?
View 4 Replies
Similar Messages:
Jul 23, 2010
Can someone explain to me the rules around what can and cannot be evaluated/inserted into markup using the <%# %> and <%= %> tags in asp.net?When I first discovered I could inject code-behind variables into mark-up using <%= I thought 'great'. Then I discovered that if such tags are present you can then not add to the controls collection of the page (that's a whole different question!). But <%# tags are ok.
Is there a way I can inject a code-behind variable or function evaluation into the page using <%# ?
View 2 Replies
Mar 17, 2010
I currently work on an in-house 'CMS' that is fairly old. It has one 'content' field where the html of a CKEditor is saved and presented to each content page.
What I would like to do is be able to replace some special tags with the output of a control. So for example:
The content string would be
[Code]....
Then, when rendering the page, replace the '[%LatestNews(to=2010/01/01)%]' with the result of a user control. The user control may contain a asp:Repeater control or something that lists the required content.
View 3 Replies
Feb 3, 2011
I am creating a custom control and was wondering if it is possible to render any JavaScript in the head tags of the page it is placed on? I am thinking I would need to use the FindControl method, but am not sure what I need to bind to. I am thinking the page object? Let me know if I am thinking in the right direction or if there is another option.
My only concern with the above mentioned idea is that how do I render all my content while placing some code in the head tags?
View 2 Replies
Apr 30, 2010
how can i add a javascript file to the page head from a user control?
View 2 Replies
Jul 29, 2010
I'm successfully using a masterpage for all my .aspx's... the below is typical... where though can I place script such as this into my .aspx below since I don't really use a head/body?:
[code]....
View 5 Replies
Feb 2, 2010
Here is the contents of my test.ascx file:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="test.ascx.cs" Inherits="UserControls_test" %>
<p id="XXX">aaa</p>
and here is the contents of my test.ascx.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UserControls_test : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.XXX.InnerHtml = "BBB";
}
}
I get an error when I refer to the id, "XXX" (underlined above) in code behind which reads: 'UserControls_test' does not contain a definition for 'XXX' and no extension method 'XXX' accepting a first argument of type 'UserControls_test' could be found (are you missing a using directive or an assembly reference?)
I have tried XXX.InnerHtml and I have tried this.XXX.InnerHtml and get same problem.
How do I successfully refer to ID'ed HTML elements in code behind?
View 2 Replies
Sep 5, 2010
I tried to use user.identity.name in a master page code behing but intellisense doesn't recognize it.
If I change Inherits masterpage to inherit page then intellisense accepts it. What's going On?
View 2 Replies
May 23, 2010
I have a tricky problem and I'm not sure where in the view rendering process to attempt this. I am building a simple blog/CMS in MVC and I would like to inject a some html (preferably a partial view) into the page if the user is logged in as an admin (and therefore has edit privileges).
I obviously could add render partials to master pages etc. But in my system master pages/views are the "templates" of the CMS and therefore should not contain CMS specific <% %> markup. I would like to hook in to some part of the rendering process and inject the html myself.
how to do this in MVC? Where would be the best point, ViewPage, ViewEngine?
View 2 Replies
Aug 3, 2010
I have a simple, but probably common problem on how to inject HTML inside an ASP.NET MVC master page. I have a google analytics tracking code that sits on my master page. The code looks like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-1']);
_gaq.push(['_trackPageview']);
// need to inject ecommerce code here
(function () {
// google analytics code here
})();
I'm using ecommerce tracking and I want to inject the "cart" information in side this HTML on the receipt page (and ONLY on this page). So I do something like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-1']);
_gaq.push(['_trackPageview']);
<% if(ViewData["googleanalytics"]!=null) {%>
<%= ViewData["googleanalytics"] %>
<% } %>
(function () {
// google analytics code here
})();
Then in the controller, I have code that looks like this:
[HttpGet]
public ActionResult Receipt()
{
var receipt = // get receipt model
// get google analytics javascript. This function pulls
// the data from the receipt model
ViewData["googleanalytics"] = GetAnalyticsInfo(receipt);
return View(receipt);
}
View 4 Replies
Mar 11, 2010
I have several hundred html files that I want to remove the <head></head> tag from and all information contained in the tag. I am fairly sure I can do this in Visual Studio using the Find and Replace In Files with REGEX.
View 5 Replies
Jan 3, 2011
remove link in the head tag of html page
[Code]....
View 2 Replies
Jul 18, 2010
i have user control (Menu) that page in it are Dynamic when i put it into the master page the menu not appear ?? how can i put user control into MasterPage
View 7 Replies
Sep 16, 2010
I have written a t4 template that basically replaces the work done by StronglyTypedResourceBuilder to give design time access to string resources as properties of classes, one class per resource file. Why? Well I needed to add some customer code that handles string token substitution and a few other customizations. Anyway, the template is working out really well and I may blog on it soon.
In the mean time though, following a common pattern, I have one .resx file for each view, master page, controller, etc. I would really like my t4 template to add a property to each such entity that gives quick access the custom resource class associated with it. For controllers this is easy. T4MVC is ensuring that they are a all declared partial. All I need to do is create the appropriate partial class in my output that declares a readonly property that returns an instance of the appropriate generated resource class.
The Problem:
I would like to do the same thing, inject generated code, into my views. Were this traditional ASP.Net, each .aspx page would have a .aspx.cs page and possibly an .aspx.designer.cs page that are all partial classes extending in the aspx page's class definition. There is no such thing by default in MVC and for good reason. However, I think for my purposes, if there is a way to do this, it would be the way to go.
I could subclass ViewPage and add a generic type parameter and a property that returns the class of that type but that has certain complications. I think adding auto generated code to each view via partial class (that is what partials are for after all) is the way to go.
I have made a basic attempt. I have created a .aspx.cs file for a view and placed a code behind attribute in the page declaration but the class generated from the view seems to reside in a different assembly any my "partial class" ends up as its own class in the same assembly as all my other code.
View 2 Replies
Jul 2, 2010
I'm new to .net, and I've noticed that when viewing my HTML source code generated by a .net application the carriage returns are removed from the head tag when it has runat="server" attribute on it.
I remove the runat="server" and the returns... return.
This really looks nasty when you have a few javascript and css files in your header because it ends up making the entire contents of the head tag 1 big line.
Just wondering if there's a way to control this or tell .net through configuration not to mangle the output?
View 4 Replies
Aug 3, 2010
I am currently working on an application implementing custom localization features. I have created a number of web user controls for different activities on user designed pages. I wish make my webcontrols to check if the page using the control is a simple page or content page of a master page. In case of simple page we need to change page direction from ltl to rtl. In case of content page we need to change direction of master page.
View 3 Replies
Oct 30, 2010
how to inject HTML code into text field and load it into the view,
I am giving the user the possibility to add/edit text on the page using Text-Box control.
My goal is to let the user add Url link into the page. Example:
The user enter the word "[[About us]]" and the system needs to translate it into
[Code]....
In the view i am using encoding: Html.Encode(Model.Page.Description).
I can write in the controller a method that will send to the view the correct syntax.
But the view encode all information therefore it's not working.
How sould i inject html code into existing text and load it into the view correctly ?
View 8 Replies
Feb 1, 2010
I'm building an asp.net app using themes, and I've assigned a theme to the app using the web config.
I have a bookmark icon that I want to use for my page and it is located in the themes directory, but I am having trouble referencing the themes location from a link tag in my header.
First I tried putting a code block inside the link tags href element, which did not work. Instead all it did was html encode the <% characters and output it directly to the browser:
<link rel="shortcut icon" href="/App_Themes/<%=Page.Theme %>/images/bookmark.ico" type="image/x-icon" runat="server"/>
I am able to put a code block inside an element in an hr tag though, so I don't know why it won't work in a link tag:
<hr test="<%=Page.Theme %>"/>
Then I tried doing a Response.Write inside the head tag, but I got an error saying the Controls collection cannot be modified because the control contains code blocks:
<% Response.Write("<link rel="shortcut icon" href="/App_Themes/" + Page.Theme + "/images/bookmark.ico" type="image/x-icon"/>"); %>
I also tried it just with a string literal, and got the same error:
<%= "<link rel="shortcut icon" href="/App_Themes/" + Page.StyleSheetTheme + "/images/bookmark.ico" type="image/x-icon"/>" %>
Is there any way to reference something from the themes directory inside the link tag?
I'm trying to do this in both an ASP.NET 2 and an ASP.NET 2 MVC app.
View 3 Replies
Feb 2, 2010
I have a Master Page that has several User Controls on it. The MasterPage code behind does some work to calculate a value that needs to be used in all of the UserControls. From the UserControl code behind, how do I access the public property of the MasterPage that I have set?
View 2 Replies
Aug 23, 2010
On my master page , I have "Search textbox" and "Search Button".On My content page , I have a "User Control" which has a "GridView".It shows some data about Vendors.Also, on this User Control's Page Load, i have code written to display all vendors in GridView.Now, when user enters Vendor Number in "Search textbox" , and hits "Search Button" , i want to handle this event inside my User Control.How to do this ?
View 2 Replies
Jun 11, 2010
I have to access the parent form's controls inside an event handler method on my user control's code behind.
View 4 Replies
Jan 17, 2010
I have a little doubt about creating a login control in the master page within a contentplaceholder.
What i want is to create my own login control in the masterpage, using a loginview inside a contentplaceholder. The code is the following:
[Code]....
So far so good, but now i want to create the logic to do the actual login. In a regular aspx page i'll do it in the cmdlogin click event, but as i'm in the masterpage, i'm not sure if i can do that. I actually tried to do it in the code behind of the masterpage, but it didn't work. What can do?? do i ahve to use the asp.net login control?
View 4 Replies
Aug 19, 2010
On my master page , I have "Search textbox" and "Search Button".
On My content page , I have a "User Control" which has a "GridView".It shows some data about Vendors.
Also, on this User Control's Page Load, i have code written to display all vendors in GridView.
Now, when user enters Vendor Number in "Search textbox" , and hits "Search Button" , i want to handle this event inside my User Control.
How to do this ?
View 2 Replies
Feb 2, 2010
I'm working on a project that uses a master page. When the page loads I'm calling a class (which I feed and ID into) to get back certain values for a location that the user has selected. Things like town name etc.
On the home page I have a user control which has some statistics for that location too.
Is there a way that I can get the user control to pull values from the class invoked by the Master Page (which has already been fed the ID, hit the db and pulled back the values), rather than creating a new instance of the class within the user control and having to supply the ID and hit the db all over again? This is now I'm calling the class in the masterpage. I have a method "CheckForStoredLocation" that goes off and gets all the data I need.
[Code]....
View 4 Replies
Dec 9, 2010
Is it at all possible to inject a request into IIS for a page, have IIS and ASP.Net handle it as normal, but get the response as html handed back to me programmatically?
Yes, I know that I could connect to port 80 using WebRequest and WebResponse, but that becomes difficult if you are accessing the IIS server from the same physical machine (loopback security controls et al).
Basically, I want to inject the request (eg for [URL]) between the points at which IIS would normally talk to the browser, and the point at which it would route it to the correct ASP.Net application, and get a response back from IIS between the points at which ASP.Net/IIS applies the httpfilters and hands the html back to the browser.
I'm predominantly working with IIS7 so if there is a solution that works just for IIS7 then thats not an issue.
View 2 Replies