If you can't add ASP includes in SharepPoint 2010... Then what? - asp.net

I'm having an extremely difficult time trying figure how to implemented some type of way to use ASP includes in SharePoint 2010. If you can't please please please help me with another way of doing so.
I found a solution, but I'm not completely happy with..
============HTML============
<div class="js-include" title="test.html"></div>
============JQUERY============
$(function () {
//Trigger global pages
$(".js-include").each(function(){
var inc=$(this);
$.get(inc.attr("title"), function(data){
inc.replaceWith(data);
});
});});

See The Case of Server Side Includes in Sharepoint Continued for an example of how to use the XML Web Part to duplicate in SharePoint what the <!-- #include file --> directive accomplishes in ASP.
However, as #PaulLeigh said, since SharePoint is built upon ASP.NET, I would highly recommend embracing Master Pages and user controls as replacements for ASP styled server side includes.

Related

Tagging Input for that works with ASP.Net

I'm playing with jquery tagit plugin at http://webspirited.com/tagit/. It's perfect for what I need but I can't get it to update the asp:BulletList because it's a server control.
I know there are workarounds by using ajax/updatepanel but I need something will work the the same way as other controls during the postback.
Are there any controls for asp.net does allows tagging?
I also used jQuery tagit when building my site...and I ran into the same issues you are describing. I managed to overcome all the issues and get it to work, but it was definitely not developer-friendly. In the end, we replaced the update panels with ASP.NET Web API's for partial page rendering (this is how you should be doing it by the way), and created our own tagging plugin. The jQuery Tagit plugin definitely has a few bugs, so creating our own was ultimately the best solution. Here's the problems you'll run into with jQuery Tagit and Update Panels...
Javascript loses references on update panel refresh
Firstly, when the update panel refreshes, you lose all javascript references. You can refresh these references by redefining them at the end of the page request. You can use a page request manager for accomplishing this. Here is an example:
Add a function to your javascript that redefines all javascript references located within the update panel:
<script type="text/javascript">
function contentPageEvents(){
var myTagitDiv = $('.myTagitDiv')
}
</script>
Then at the end of your page you can add this:
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(contentPageEvents);
</script>
ASP.NET changes the IDs of its server-side controls
In order to reference an ASP.NET control, you must either use ClientIdMode="Static", or reference the CSS class of the control rather than the ID. ASP.NET controls have almost the same level of customizibility as normal HTML controls as long as you use the CssClass attribute effectively.
Don't use Update Panels
In the end, you really shouldn't be using update panels at all. The ASP.NET update panel is designed to simulate partial page rendering, but does not actually perform it. If you plan to build a decent web site and want to use partial page rendering, you should start looking into using the new Web API Controller class that comes with MVC 4. This amazing tool can be easily implemented in a Web Forms project. It is built-in in Visual Studio 2012, and can be downloaded for use in Visual Studio 2010. Here is a link to a tutorial on how to create a web api that can post items to a database:
asp.net mvc - Posting JSON data via jQuery to ASP.NET MVC 4 controller action (Stack Overflow)

JQuery-Mobile and ASP.Net - AJAX or Postback?

I've been developing ASP.Net for the past and until recently come across a mobile project. Jquery-Mobile seems perfect as a framework for this, so I just dived into it.
Currently I'm using ASP.Net approach to put server controls on a page, then use jqm to enhance those controls to make them looks mobile. I actually do postback to collect form data and process them in code-behind.
To avoid a full page refresh, I had to mix them with updatepanel too. Somehow I got them working but deep down I just feel this isn't the right way (or efficient way) of doing it.
There's too much complication of mixing things up to get them right, so I think maybe I should just avoid postback and do everything-else in pure AJAX requests?
$.ajax({
type: 'POST',
url: "/GetName",
data: "{}",
contentType: "application/json; charset=utf-8"
})
.success(function (response) {
alert(response);
});
Code-behind:
[WebMethod ()]
public String GetName()
{ return "Jack"; }
Questions:
This works, but is this the better way to go with jQuery-Mobile websites, or this is just another bad example?
Is UpdatePanel and postback a bad idea for this scenario? (I know they work)
If AJAX is preferred, how do I go about populating a dropdownlist on pageload (Not server control)? Sending an AJAX request to populate dropdownlist on $(document).ready() seems stupid to me
What I'm looking for is rules of thumb of developing a mobile site, I don't want to steer too far away from what should be doing right. Your inputs are very much appreciated. Thanks.
asp.net Web Forms and jQuery Mobile really don't work together. The postback model breaks the way that jQuery Mobile ajax works and it will fall appart when you have more than a single page or form. Specifically Web Forms requires a single <form> tag that wraps all server side controls and you cannot introduce additional "internal" forms. jQuery Mobile really works best with the ajax model and one or more "pages" (<div data-role="page">) and forms that are contained within the DOM. Update panels will ultimately cause chaos.
One approach is to simply turn off jQuery Mobile ajax loading. You can do that with this:
//note that the order of script loading here is critical.
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
$(document).bind(“mobileinit”, function() {
$.mobile.ajaxEnabled = false;
});
</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js">
</script>
but in the end, you won't have a highly efficient web site. If you site is running over a local wireless network, it may be good enough.
I work in a mostly Web Forms environment and had a need for a Web Forms based jQuery Mobile app and coded 5 or so "pages" as a single static html file. I then relied on JavaScript and jQuery ajax loading to ASMX web service end points. I also made extensive use of KnockoutJS but I certainly could have relied solely of JavaScript and jQuery ajax to pull data (and in my case, the app was of a reporting nature with no data updating.) If you are saving data, you can use the same technique.
An even better approach is to go with asp.net MVC which eliminates the forced postback model and allows fine grained control over where your <form> tags are placed.
I am working on a larger mobile site and using MVC for the back end and taking full advantage of Razor views but in the end, I am relying on client side ajax calls for all data and KnockoutJS for almost all dynamic markup. In the end, my client side app isn't all that different between Web Forms and MVC. MVC based controllers are easier to work with for ajax end points and the solution is cleaner.
In general, I would lump both solutions into the "single page application" aka SPA approach. There are other approaches that might work with Web Forms but in my limited exploration, this was the best option.

Is MVC 2 client-side validation broken in Visual Studio 2010 RC?

I can't seem to get client side validation working with the version of MVC released with Visual Studio 2010 RC.
I've tried it with two projects -- one upgrade from 1.0, and one using the template that came with VS.
I'd think the template version would work, but it doesn't. Added the following scripts:
<script type="text/javascript"
src="<%= Url.Content("~/Scripts/MicrosoftMvcValidation.js") %>">
</script>
<script type="text/javascript"
src="<%= Url.Content("~/Scripts/jquery.validate.js")%>">
</script>
which are downloaded to the client correctly. Added the following to my form page:
<% Html.EnableClientValidation(); %>
<%--yes, am aware of the EndForm() bug! --%>
<% using (Html.BeginForm()) { %>
<%--snip --%>
and I can see the client validation scripts have been added to the bottom of the form. But still client validation never happens.
What is worse is that in my upgraded project, the client validation scripts are never output in the page!
PLEASE NOTE: I am specifically asking about the version of MVC2 that came with VS2010 RC. Also, I do know how to google; please don't waste anybody's time searching and answering if you aren't familiar with this issue in the release candidate of Visual Studio. Thanks.
Error ID10T: User editing one page and testing another.
However, I can't get client-side validation working on the MVC2 template project. If anybody has an idea how to, say, get it working for the registration page, please answer.
I had the same problem also,
the examples by MS(scottGu and haacked) are a bit confusing since you don't really know on which version they are talking about, and haacked updates his post every time a new version is out so you it's not relevant to you :(.
To make jQuery validation work On VS 2010 do the following:
as you answered you need the MicrosoftMvcJQueryValidation.js file, several ways to get this file, i got it from the example project from haacked post: ASP.NET MVC 2 Custom Validation
remove all JS references and leave just this one and the jquery.validate.min.js
call <% Html.EnableClientValidation(); %> before the opening tag of the form
Dont forget to put some Html.ValidationMessageFor(.. on your fields since this is the trigger for adding the enteries to the client validation JSON object
i guess you did all the above, but left the references to MicrosoftMvcValidation.js on the page, notice at the end of this file there is the hook to the MS client side validation.
funny i just wanted to blog about this issue this morning and found your question,\hope this helps
I have had no luck getting this to work in MVC 2 RC. According to other questions here on SO, you have to get the MicrosoftMvcJQueryValidation.js file from the MVC Futures release, hold your left foot behind your head, and whistle Dixie for half an hour. I did this and more and have not been able to make it work.
I have, however, gotten it working by using the jQuery Validation plugin directly. More work, but it gets the job done.
Hopefully it will be fixed in RTM.

How to implement A simple AJAX call using asp.net page?

I'm trying to implement this specific example using asp.net page instead of asp page.
If you look at the example you can see that there are 2 parts for the page:
Mail asp page. This page have JS code that calls other asp file for AJAX use.
the other asp page which holds the JS code.
The responseText of the call is the client side code, so, when I write something like this:
<html><head><title>test</title><script language="javascript" runat="server"
type="text/javascript">function test(){Response.Write("This is a Test!");
</script><body onload="test()"></body></html>
the page ignores my server side code and returns this:
<html><head><title>test</title><body onload="test()"></body></html>
what should I need to do to make him process my JS code and return its output?
Thanks in advance,
Oz Radiano.
asp.net does not process javascript server side, so setting the script tag runat=server with language="javascript" will be mostly ignored.
I think if you change it to "JScript" it will work, however, this has nothing to do with ajax.
"runat = server" says, preprocess this on the server and don't send it to the client.
If the language is a processable one it will be evaluated as well.
Try implementing the example after watching some videos from http://www.asp.net/learn/ajax-videos/ and http://www.asp.net/learn/ajax/
Its very easy to implement AJAX in asp.net then ASP. I can clearly give you the correct source code. :) But you seem to try out new things. Let us know how it goes!
Thanks for your responses, they made me understand that I'm not sure what my problem is.
After failing in implementing this exact example, I've googleed "how to run asp code using ajax"
this result returned and made it very clear.
Thanks again.

De-cluttering ASP.NET javascript

I'm just getting into ASP.NET Been avoiding it for years as I'm a desktop application advocate.
Anyway, I was wondering if there's a way to stop the generated html being so cluttered with javascript. Is there a way to make the generated script go into a referenced js file rather that inline with the page.
Look into ASP.NET MVC - it is an alternative to WebForms and tends to have less clutter.
Are you sure you're using code-behind?
When you add a new page, make sure you check "Place code in a separate file", otherwise all your server-side code will be on the page (even tough it won't show up for the end-user)
If you're using code-behind but it still has a lot of javascript code in the page (maybe you're using ajax?) I'd suggest you don't use the .NET ajax controls, just do all the ajax by hand, using jQuery or Prototype. It's fast and it'll be as lightweight as it can be.
Check out ClientScriptManager.RegisterClientScriptInclude.

Resources