Again, I've looked around to try to find some posts on this and there are many but none that address my specific question (that I could find).
What I am looking : I have a projects and it loads different pages (.aspx) in an iframe dynamically. Now I am trying to remove iframe and add a div and load aspx pages inside that div, using this :
$("#containerDiv").load("test/default.aspx", function () {
});
it loads aspx page easily but I am unable to execute C# code which is written in default.aspx.cs may be its not a good practice but I want to know is there any solution of my problem.
$.load will not your c# code why because it load only the contents of your aspx page not of aspx.cs.
Use user controls instead.
If need help how to implement user control refer this link.
Related
Somehow i have lost my source code but i have published project in precompile state on my hosted server. i am able to recover c# code using decompilers but unable to find the aspx pages code as they are in compiled form. when i view them in decompiler they just show me the C# code of aspx page which is not helping me.
Initially i decided to reconstruct them on the basis of GUI but its taking too much time. My questions is , is this possible i can use the html source of page instead of its actual aspx code ? i have the c# code for my page but no aspx code so if its possible just to copy the html in aspx file and try to run if this works?
I'm having a web application project which is running .NET 4.0. I've plenty of .aspx page and now I would like to add in a block of script code to all the .aspx page header, for example Google Analytics.
I know there is a solution to do is add in every single page, but I would like to know is there any other's way to do this instead modify every single .aspx page?
*My header is not runat server
I got an idea to do but not sure it's work or not.
Get the page class in Global.asax
Get the output stream from the page class.
Insert the Google Analytics code in the HTML header.
I couldn't get the Page.Response in the Global.asax as I tried in the Application_PostRequestHandlerExecute & also Application_EndRequest. Does anyone know is this work and how it's work?
Thanks.
Use master pages. This is the ASP.NET way of putting the same content on multiple pages without repeating yourself.
All of our aspx pages code-behind classes inherit from the same base class, which allows us to inject standard client side elements (controls, script, etc) into every page using a single point of control.
Our design was implemented before the advent of master pages, but while it could possibly be converted to a master-page design, we have found this implementation to be extremely flexible and responsive to changing needs.
For example, we have two completely separate application designs (different skin, some different behavior) that is based off of the same code base and page sets. We were able to dynamically swap out banners and other UI and script elements by simple modifications to the base class in order to support this without having to duplicate every page.
Unfortunately, if you want the script to be in the head element, you will need to ensure that they are all marked as runat=server.
Our base class itself inherits from Page, so it can intercept all of the page's events and act on them either instead of or in addition to the inheriting classes (we actually have internal overrideable methods that inheritors should use instead of the page events in order to ensure order of execution).
This is our (VB) code for adding script to the header (in the Page's LoadComplete method):
' sbscript is a stringbuilder that contains all of the javascript we want to place in the header
Me.Page.Header.Controls.Add(New LiteralControl(sbScript.ToString))
If it is not possible to change the heads to runat server, you could look into ClientScriptManager method RegisterClientScriptBlock which places the script at the top of the page.
You can create a basic page with the header with the custom code such as Google analytics and have the other pages inherit from that. It will facilitate two things:
1) In case you ever want to change the custom code you will only have to do it in one place
2) No repetitive code hence more maintainable
I am trying to do the same thing on a legacy app that we're trying to decommission. I need to display a popup on all the old pages to nag users to update their bookmarks to use the new sites, without forcing them to stop using the legacy site (yet). It is not worth the time to convert the site to run on a master page when I can just plop in a popup script, since this whole thing is getting retired soon. The main new site uses a master page, which obviously simplifies things there.
I have this line in a file that has some various constants in it.
Public Shared ReadOnly RetirementNagScript As String = "<Script Language='javascript'> alert('[app name] is being retired and will be shut down [in the near future]. Please update your bookmarks and references to the following URL: [some URL]'); </script>"
Then I am inserting it in Global.asax, in Application_PostAcquireRequestState:
Response.Write(Globals.RetirementNagScript)
Hopefully this is useful to you; I still need to be able to present a clickable URL to the user that way, on each page of the legacy site, and JS alert doesn't do that for me.
The problem I'm facing is getting the ribbon to open up automatically when I load a page, say I click on the 'Customer Info' link in the quick launch menu, I'd like the ribbon for the Customer Info page to appear upon loading the page.
We have some javascript that does this on custom pages with webparts, seen below:
<script type="text/javascript">
$(document).ready(function () {
WpClick({
srcElement: $(".s4-wpcell").get(0),
target: $(".s4-wpcell").get(0)
});
$(".item-select").click(function () {
RefreshCommandUI();
});
});
The pages I'm trying to do it on are just your run of the mill SharePoint pages with the 'add new item' link etc. Is there a way to do this through the schema file? Or is there some way to put the javascript code above into the schema file so it does this?
I'm open to suggestions.
Thanks!
I think you have a couple of options.
If you need the ribbon to always be open on page load within that site then put the javascript in your masterpage for that site (this may mean you need to create a custom masterpage deriving from the one you have now that includes this javascript)
If this is on a small number of pages (and the number isn't going to grow in the future) then I would recommend just putting the javascript in a content editor webpart. This can be hard to maintain if you expect this requirement for a lot of newly created pages on the site.
If you need to have the ribbon loaded for a number of page types look into creating custom page layouts for these page types (if you haven't already) and add the javascript to the page layouts you need it for. This may not be a good option if you are working with a bunch of pages that are already created using the out of the box templates as you would need to do some sort of migration to the new page layout.
I have one HTML file containing several <div> elements. I want to refresh just part of the page using either JavaScript or C#. Can someone help?
I am trying to do it this way:
document.location.reload(document.getElementById("contentdiv"));
It reloads the whole page. I wish to reload contentdiv. If contentdiv is at the middle of the page then it should load only that part.
Thank you.
You could move the contents of everything you want reloaded into an external file, and either use the <iframe> tag and only refresh that frame, or you could use JavaScript and refresh the div with Ajax.
Ajax isn't that simple to explain in a short answer, but you can find plenty of information on it here: http://www.w3schools.com/Ajax/ajax_example.asp or if you use a framework like jQuery ajax is much easier.
iFrames can be implemented (on mypage.html, for example) like so: <iframe src='mypagecontent.html'></iframe> and in mypagecontent.html you could use <script type='text/javascript'>window.location.reload();</script> to refresh the frame.
Not sure if this is what you're looking for, but hope it helps somewhat.
What ASP.NET Framework are you using? If you are using Web Forms, look into UpdatePanel
how we can create the dynamic page ex. help.aspx and write the code in sitefinity. Because i facing a problem I create a page but i unable to know in which directory the page is lived. If any one help me Suggest.
http://abc.com/sitefinity/admin/pages.aspx
I'm not exactly sure I understand your question correctly. When you create a page in Sitefinity, it doesn't create an ASPX file. The data for the page is kept in the database and served from there. There are no physical files involved.
If you want to write some code that executes when a page loads, you have two options:
Put the code into a control and drop the control on a page created from within Sitefinity
Create a regular ASPX page from Visual Studio and include it as an external page in Sitefinity.
I would recommend the first option, as this would provide you with all the Sitefinity goodness that all pages use - templates, editing through the browser, etc.
If you wanted something else and I misunderstood, please be more specific.
Slavo, The Sitefinity Team