ASP.NET 4.5 Hosting :: Enabling Unobtrusive Validation From Scratch in ASP.NET 4.5 Webforms

asphostportalbanner-e1430121991200ASP.NET 4.5 Hosting :: Enabling Unobtrusive Validation From Scratch in ASP.NET 4.5 Webforms  – I used to be fiddling with ASP.NET 4.5 and Visual Studio 2012 particularly with all the new Validation attributes and i identified they function great, specially the new unobtrusive validation, then I attempted to permit this sort of validation over a new Vacant Net Software, and that i identified that this just isn’t out-of-the-box, you’ll need to create some configurations to your Net Application.

You’ll find a few ways to allow the unobtrusive validation over a Internet Software:
Through the web.config file
<configuration>
<appsettings>
<add key=”ValidationSettings:UnobtrusiveValidationMode” value=”WebForms”>
</add></appsettings>
</configuration>
Via the Global.asax file

protected void Application_Start(object sender, EventArgs e)
{
ValidationSettings.UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
}
On each page:

protected void Page_Load(object sender, EventArgs e)
{
this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.WebForms;
}
To disable the unobtrusive validation set the UnobtrusiveValidationMode property to None. Unobtrusive validation is actually enabled by default in ASP.Net 4.5.

We’ll start with a simple example, create an Empty Web Application and add a MasterPage called Site.master and a content page for this master called Default.aspx.
Add the following code to the Default.aspx file:
<asp:TextBox runat=”server” ID=”txt” />
<asp:RequiredFieldValidator ErrorMessage=”txt is required” ControlToValidate=”txt” runat=”server” Text=”*” Display=”Dynamic” />
<asp:Button Text=”Send info” runat=”server” />
If you try to run a simple ASPX page using a validator, the following exception will be thrown:

“WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for ‘jquery’. Please add a ScriptResourceMapping named jquery(case-sensitive)”. Before fixing this, let’s disable the unobtrusive validation to see the result.

On the page:
protected void Page_Load(object sender, EventArgs e)
{
this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
}
Now run the page and the validation will work as it used to work in ASP.Net 4.0 If you examine the rendered HTML, you will see that the gross inline script is rendered:
<script type=”text/javascript”>
//<![CDATA[
var Page_Validators = new Array(document.getElementById(“ContentPlaceHolder1_ctl00″));
//]]>
</script>

<script type=”text/javascript”>
//<![CDATA[
var ContentPlaceHolder1_ctl00 = document.all ? document.all[“ContentPlaceHolder1_ctl00”] : document.getElementById(“ContentPlaceHolder1_ctl00”);
ContentPlaceHolder1_ctl00.controltovalidate = “ContentPlaceHolder1_txt”;
ContentPlaceHolder1_ctl00.errormessage = “txt is required”;
ContentPlaceHolder1_ctl00.display = “Dynamic”;
ContentPlaceHolder1_ctl00.evaluationfunction = “RequiredFieldValidatorEvaluateIsValid”;
ContentPlaceHolder1_ctl00.initialvalue = “”;
//]]>
</script>
<script type=”text/javascript”>
//<![CDATA[

var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == “function”) {
ValidatorOnLoad();
}

function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
else {
return true;
}
}

document.getElementById(‘ContentPlaceHolder1_ctl00’).dispose = function() {
Array.remove(Page_Validators, document.getElementById(‘ContentPlaceHolder1_ctl00’));
}
//]]>
</script>
Now let’s re-enable the unobtrusive validation. In order to fix the previous exception, we need to install the following Nuget packages: (I like to install jQuery first to get the latest version, although this is not required.)
jQuery
ASPNET.ScriptManager.jQuery
Microsoft.AspNet.ScriptManager.MSAjax
Microsoft.AspNet.ScriptManager.WebForms
At this point, if you run the application again, the exception will be gone =) how cool eh?. This is because the following Nuget packages automatically register the scripts needed with the ScriptManager control.

Let’s examine the code added by these Nuget packages using ILSpy:

AspNet.ScriptManager.jQuery
public static class PreApplicationStartCode
{
public static void Start()
{
string str = “1.8.1”;
ScriptManager.ScriptResourceMapping.AddDefinition(“jquery”, new ScriptResourceDefinition
{
Path = “~/Scripts/jquery-” + str + “.min.js”,
DebugPath = “~/Scripts/jquery-” + str + “.js”,
CdnPath = “http://ajax.aspnetcdn.com/ajax/jQuery/jquery-” + str + “.min.js”,
CdnDebugPath = “http://ajax.aspnetcdn.com/ajax/jQuery/jquery-” + str + “.js”,
CdnSupportsSecureConnection = true,
LoadSuccessExpression = “window.jQuery”
});
}
}
Microsoft.AspNet.ScriptManager.MSAjax
public static void Start()
{
ScriptManager.ScriptResourceMapping.AddDefinition(“MsAjaxBundle”, new ScriptResourceDefinition
{
Path = “~/bundles/MsAjaxJs”,
CdnPath = “http://ajax.aspnetcdn.com/ajax/4.5/6/MsAjaxBundle.js”,
LoadSuccessExpression = “window.Sys”,
CdnSupportsSecureConnection = true
});
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjax.js”, “window.Sys && Sys._Application && Sys.Observer”);
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjaxCore.js”, “window.Type && Sys.Observer”);
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjaxGlobalization.js”, “window.Sys && Sys.CultureInfo”);
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjaxSerialization.js”, “window.Sys && Sys.Serialization”);
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjaxComponentModel.js”, “window.Sys && Sys.CommandEventArgs”);
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjaxNetwork.js”, “window.Sys && Sys.Net && Sys.Net.WebRequestExecutor”);
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjaxHistory.js”, “window.Sys && Sys.HistoryEventArgs”);
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjaxWebServices.js”, “window.Sys && Sys.Net && Sys.Net.WebServiceProxy”);
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjaxTimer.js”, “window.Sys && Sys.UI && Sys.UI._Timer”);
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjaxWebForms.js”, “window.Sys && Sys.WebForms”);
PreApplicationStartCode.AddMsAjaxMapping(“MicrosoftAjaxApplicationServices.js”, “window.Sys && Sys.Services”);
}
private static void AddMsAjaxMapping(string name, string loadSuccessExpression)
{
ScriptManager.ScriptResourceMapping.AddDefinition(name, new ScriptResourceDefinition
{
Path = “~/Scripts/WebForms/MsAjax/” + name,
CdnPath = “http://ajax.aspnetcdn.com/ajax/4.5/6/” + name,
LoadSuccessExpression = loadSuccessExpression,
CdnSupportsSecureConnection = true
});
}
Microsoft.AspNet.ScriptManager.WebForms
public static void Start()
{
ScriptManager.ScriptResourceMapping.AddDefinition(“WebFormsBundle”, new ScriptResourceDefinition
{
Path = “~/bundles/WebFormsJs”,
CdnPath = “http://ajax.aspnetcdn.com/ajax/4.5/6/WebFormsBundle.js”,
LoadSuccessExpression = “window.WebForm_PostBackOptions”,
CdnSupportsSecureConnection = true
});
}
As you can see these Nuget packages automatically register the scripts using the ScriptManager object (besides installing the required JavaScript files)

Run the application and examine the rendered HTML. You will note that it’s much cleaner now, in this case the inline script has been moved to an external file that can be rendered using bundles to increase performance. The rendered script looks like:
<script src=”Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js” type=”text/javascript”></script>
<script src=”Scripts/jquery-1.8.1.js” type=”text/javascript”></script>
Much better right?. Notice how ASP.Net used HTML5 custom attributes:
<input name=”ctl00$ContentPlaceHolder1$txt” type=”text” id=”ContentPlaceHolder1_txt” />
<span data-val-controltovalidate=”ContentPlaceHolder1_txt” data-val-errormessage=”txt is required” data-val-display=”Dynamic” id=”ContentPlaceHolder1_ctl00″ data-val=”true” data-val-evaluationfunction=”RequiredFieldValidatorEvaluateIsValid” data-val-initialvalue=”” style=”display:none;”>*</span>
<input type=”submit” name=”ctl00$ContentPlaceHolder1$ctl01″ value=”Send info” onclick=”javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentPlaceHolder1$ctl01&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))” />
The data-val-* are custom attributes used by the unobtrusive validation engine

If you click the button to trigger the validation you will be pleased to see that it works as expected…but we are not done yet =/

The settings we have applied won’t work if you intend to use an UpdatePanel control (yeah the evil UpdatePanel again…). This is because this control requires a ScriptManager control on the page (or MasterPage) and we do not have any yet. So let’s add a simple ScriptManager control to the master page and see what happens. Add the following code to the Site.master page right under the <form…
<asp:ScriptManager runat=”server” ID=”scriptManager”>
</asp:ScriptManager>
Run the page again and fire the validation… oops… the client validation has gone =( We only have server validation. I’m not sure why this happens but my best guess is that the just added ScriptManager control is overriding our code settings.

To fix it, change the declaration of the ScriptManager control on the Site.master page to:
<asp:ScriptManager runat=”server” ID=”scriptManager1″>
<Scripts>
<asp:ScriptReference Name=”MsAjaxBundle” />
<asp:ScriptReference Name=”jquery” />
<asp:ScriptReference Name=”WebForms.js” Assembly=”System.Web” Path=”~/Scripts/WebForms/WebForms.js” />
<asp:ScriptReference Name=”WebUIValidation.js” Assembly=”System.Web” Path=”~/Scripts/WebForms/WebUIValidation.js” />
<asp:ScriptReference Name=”MenuStandards.js” Assembly=”System.Web” Path=”~/Scripts/WebForms/MenuStandards.js” />
<asp:ScriptReference Name=”GridView.js” Assembly=”System.Web” Path=”~/Scripts/WebForms/GridView.js” />
<asp:ScriptReference Name=”DetailsView.js” Assembly=”System.Web” Path=”~/Scripts/WebForms/DetailsView.js” />
<asp:ScriptReference Name=”TreeView.js” Assembly=”System.Web” Path=”~/Scripts/WebForms/TreeView.js” />
<asp:ScriptReference Name=”WebParts.js” Assembly=”System.Web” Path=”~/Scripts/WebForms/WebParts.js” />
<asp:ScriptReference Name=”Focus.js” Assembly=”System.Web” Path=”~/Scripts/WebForms/Focus.js” />
<asp:ScriptReference Name=”WebFormsBundle” />
</Scripts>
</asp:ScriptManager>
Run the application and our little example will work again as expected

Sadly these new settings are the equivalent to the settings added by code and we need to add them to be able to use the traditional Microsoft AJAX controls.

There’s one last thing we need to configure, this is because there’s actually a bug with the ValidationSummary control.

To test it, update the Default.aspx page as follows:
<asp:ValidationSummary ID=”ValidationSummary1″ runat=”server” />

<asp:TextBox runat=”server” ID=”txt” />
<asp:RequiredFieldValidator ErrorMessage=”txt is required” ControlToValidate=”txt” runat=”server” Text=”*” Display=”Dynamic” />
<asp:Button Text=”Send info” runat=”server” />
Now run the page again, scroll down until you can see the button and click it… woot your page jumped to the top… the workaround to solve this little bug is to add the following code to the Site.master
<script>
window.scrollTo = function () {

};
</script>

asphostportal-icon-e1421832425840-120x120-e1424663413602ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for the ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.6, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch. Click here for more information

Why SEO is Important for Your Online Business

As the web grows across the world, more and more people are getting websites, making it ever more difficult to make yourwebsite shine through the crowd. Prospective customers may not remember your web address or even your company name even if you tell them. Additionally, the whole purpose of havinga website is to bring your product or service to a wider audience than you can otherwise market.

flat-vector-design-illustration-of-modern-business-office-and-workspace-600x500

Your Prospects

Those that purchase online are “skimmers” –that is, they simply go to their favorite search engine and type in a word or phrase related to their desired product or service, and usually only look as far as the first few items on the list. If you’re really lucky, they’ll look all the way to the bottom of the first page. So where do you want to be? That’s right –way up there near the top. The closer to the top of that search engine list you get, the more people will see your website. Getting you to the top of that list is what Search Engine Optimization (SEO) is all about.

The realities of modern lifestyles and economics have lent themselves to an ever-increasing number of people seeking the convenience, variety and consumer-friendly environment that is provided by making purchases online from the comfort of their own homes, as opposed to the drive time, long lines and other hassles associated with traditional shopping approaches. As more people become internet consumers every day, the importance of creating a solid web presence is vital for your business to thrive in the 21st Century.

SEO vs. IT

A common misconception is that IT (information technology) training equates to the ability to create successful websites. This is not necessarily the case. SEO training must be undertaken as a subject in and of itself, as the I.T. field is far too generalized and geared toward the technicalities of the internet to provide the kinds of marketing tricks and skills needed to create a truly successful web presence. I.T. is definitely useful, but without the necessary marketing skills, many end up working with a half-empty toolbox when it comes to the internet.

For these reasons, those proficient in the SEO field are in an ever-increasing demand. Think about it –if you can make a website make more money, what website owner in their right mind wouldn’t search you out? A competent SEO expert is one of the hottest commodities in the online world of commerce, and always has opportunities to succeed. If you can make a customer’s website climb through to the high end of the Google rankings, you will have more opportunities than you can handle!

SEO vs. Pay Per Click

If you want to increase the traffic to your website, there are basically two ways to go; you can utilize search engine optimization (SEO) or Pay Per Click (PPC). PPC can yield results, but you have to find a way to get people to the advertisements on your site in order for them to click them in the first place. If you load your page down with a ton of advertisements due to a lack of traffic, it will take longer to load, be less attractive to visitors, and you will actually lose traffic (and revenue) in the long run. It is much better to focus your strategies around SEO to get high-volume “organic” traffic so that you can have the freedom to employ tasteful use of PPC ads that compliment your web content.

Why Do SEO Strategies Fail?

SEO is as much art as science. There are many factors involved in an effective SEO strategy. However, there are three major reasons why SEO strategies fall short.

  • Poorly-Defined Target Audience –Often, the most well-laid SEO plans crash and burn because no effort was made to determine what kinds of people would most likely search for the content on the website.
  • Lack of Proper Benchmarking –How well does your site compare with similar sites across the web? Is traffic increasing relative to them? Any proper maintenance of a successful website involves constant review of its place on the World Wide Web in relation to the competition, so that any downward trends can be caught before they’re out of control and you’re at the bottom of the heap.
  • Neglected Content Development –If you aren’t providing new, fresh information on your site, there is no reason why anyone would continue to visit. Your website should have new, original content that is engaging and targeted to the specific audience(s) you are cultivating through your SEO strategy.

asphostportalbanner-e1430121991200

Conclusion

The emerging importance of effective SEO strategy is self-evident, and its importance simply can’t be over-stressed. Effective almost by itself SEO equates to an successful website, while ineffective (or absent) strategies equally ensures almost certain failure. For this reason Article Search, the SEO field is a permanent and ever-growing aspect of the IT industry.


Need More Costumers For Your Online Store? Check Out This Tips!

BestCheapHosting.net– After you created your online store as you wanted it, now it’s time to get more and more customers for your online store to increase your product sales and revenues. There are different useful tips and tricks that can really help you improve your visits and your number of customers. So, do you need more costumers for your online store? Just check out these following tips.

6869-01-flat-design-office-2-558x313

How to Get More Costumers For Your Online Store?

Research is Important

First of all, you really need to make research, especially regarding the level of customer satisfaction so you can ask your existing customer for feedback regarding your products, website, shipment, payment and other important aspects of your business.  You can also view the reports your website is generating regarding the number and value of sales, unique visits, what products are popular and so on. After you researched you customers, websites and products it is time to research how people find your products, maybe from referrals, social media, e-mail, text messages or word of mouth. In this step you identify what your customers and business needs and you connect the dots between them. Based on your research, you can focus on the most popular products to grow sales, but also on the least popular products to change them into something more attractive.

After research, you need to focus on building a serious brand where products, features and services are well detailed and well customized so your brand is unique. This brand name and logo can be used at everything you make from reports, simulation games to products, websites and so on, making your shop even more popular.

Use Internet Marketing

One way to use internet marketing is the affiliation where you give your customers an affiliation/referral link for other people to register and you offer your customers discounts or even money in exchange. Internet service provider companies, especially hosting companies, use a lot of these marketing methods to increase their number of customers, but also to increase their number of orders for each customer. The most used method to increase customers are ads, either Google Adwords or others. You can select which type of website you want your ads on, the images and the text for your ads. You need to understand the value of time to succeed with this method, so don’t put ads at 3.00 in the morning because almost nobody will see them and you still pay them.

Consider E-Mail Marketing

Depending on the platform you use either WordPress, Magento, OpenCart or others, you can use additional plugins for newsletters and even MailChimp integration for improved newsletters. Each CMS has plugins specific for newsletters where you can create templates and to schedule messages for your customers. MailChimp also offers different reports and you can even send manual newsletters using Gmail that offers the possibility to integrate your personal e-mail with the one of your online store e-mail. Using Chrome browser and Sidekick plugin you can see statistics regarding your manual e-mail such as who opened or not the newsletter.

Connect With Your Potential Customers Through Social Media

Another very used way to increase the number of customers for your online store is social media where you really need to make accounts, profiles and pages. Some of the most popular social media networks are Facebook, Twitter, YouTube and Instagram.

Facebook

Facebook-banner

Facebook offers you a business page for your store, but you can use also create a personal profile page to promote your shop. You can even post text, images, special animated images named gifs and videos with products and news regarding your website. Depending on the CMS you use for your online Store you can use modules for Drupal or plugins for WordPress that offers the possibility to automatically send published pages to Facebook and other social media. Facebook offers reports, message center, chat and even their own ads where you can make ads with your customized images and text sending customers to your post, business page or directly to your online store. On your Facebook page, you can create special button such as Contact or Shop that sends customers directly to the specific pages. If you use special Facebook third-party apps you can improve your business page even more creating polls, feedback forms and other things.

Twitter
twitter-banner

Twitter is usually used by teenagers and has a text limitation of 160 characters exactly as a text message, but people tend to offer more attention to Twitter messages because are shorter than other messages from different social medias. In Twitter and in Facebook you can create lists of friends/followers so you can make the New York list or the Male list and so on. For short announcements and brief product spoilers you should definitely use Twitter.

Youtube

yum-yum-videos-explainer-video-production-company-youtube-banner-sm_0

Since Youtube is for videos, you can use it create tutorials, reviews, previews and even news videos for your store and host them on your channel.

Instagram
instagram-bannerInstagram is used by mobile devices and usually people put pictures with themselves but you can put a picture with you and one of your product presenting it in a funny and creative way.

Each of these social medias have one or more mobile apps for users, Facebook has even four apps, a Messenger for chat, a Page Manager for business page, a Facebook app for the wall and a Group Manager for groups where you can manage your own group created for your online store.

Optimize Your Website For Organic Web Traffic Using SEO

SEO (Search Engine Optimization) contains all the methods we already wrote, but also different techniques to write content and to structure pages such as bold, italic or underline words, keywords, descriptions, titles, friendly links, headers and so on. Also SEO has an off-site part where you manage link exchanges, banner exchanges, guest posts and other ways to send customers to your website from other ones. The most useful SEO trick is to have a blog where you can write what others wrote about your products and brand but also your own personal opinions regarding your products.


asphostportal-icon-e1421832425840-120x120-e1424663413602ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for the ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.6, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch. Click here for more information