European ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4, ASP.NET 4.5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

ASP.NET 5 Hosting - HostForLIFE.eu :: How to Highlight Dates in Calendar with ASP.NET?

clock June 26, 2015 08:48 by author Peter

In this article, I explained how to How to Highlight Dates in Calendar with ASP.NET. First step create new ASP.NET Empty web Application provides it to that means full name. Now, Add new webfrom to your project. Then drag and drop Calendar on your design page. Now. add two properties WeekendDayStyle-BackColor="Yellow", WeekendDayStyle-ForeColor="Black" to your calender control as shown below and run your application.

<asp:Calendar ID="Calendar1" runat="server" 
WeekendDayStyle-BackColor="Yellow" 
WeekendDayStyle-ForeColor="Green" ></asp:Calendar> 

And here is the output:

You can achieve the same by using (OnDayRender event) code as mentioned below. Remove WeekendDayStyle-BackColor="Yellow", WeekendDayStyle-ForeColor="Green" from Calender control.
Here is the .aspx code
<asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender"></asp:Calendar> 

CodeBehind:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) 
{  
if (e.Day.IsWeekend) 

  e.Cell.BackColor = System.Drawing.Color.Yellow; 
  e.Cell.ForeColor = System.Drawing.Color.Green;  



If you wish to spotlight on 'Monday' write the subsequent code in Calendar1_DayRender event. It highlights the the desired day dates.
if (e.Day.Date.DayOfWeek == DayOfWeek.Monday)  

e.Cell.BackColor = System.Drawing.Color.Yellow; 
e.Cell.ForeColor = System.Drawing.Color.Green;  
}

HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



ASP.NET 5 Hosting - HostForLIFE.eu :: Learn How to Uncover Silent Validation

clock June 22, 2015 07:52 by author Peter

ASP.NET validation is incredibly helpful and permits developers to confirm data is correct before it gets sent to a data store. Validation can run either on the client side or on the server side and each have their advantages and disadvantages. MVC and Webforms handle validation slightly otherwise and i will not get into those differences during this article. Instead, i'd prefer to explain some best practices and suggestions for you once implementing ASP.NET validation.

Bind Validation To HTML elements
To implement validation, you initially add an HTML element to a page, then a validation element points to it HTML part. In MVC, you'd write one thing like this for a model field known as Name.

<div class="editor-field col-md-10"> 
    <div class="col-md-6"> 
        @Html.TextBoxFor(model => model.Name, new { @class = "form-control" }) 
    </div> 
    <div class="col-md-6"> 
        @Html.ValidationMessageFor(model => model.Name) 
    </div> 
</div> 


In Webforms, write the following code:
<asp:DropDownList ID="Name" runat="server" AutoPostBack="true" FriendlyName="Option:" 
AddBlankRowToList="false" DisplayBlankRowText="False" CausesValidation="true"> 
<asp:ListItem Text="Option 1" Value="1"></asp:ListItem> 
<asp:ListItem Selected="True" Text="Option 2" Value="2"></asp:ListItem>
</asp:DropDownList> 
<asp:CustomValidator ID="valCheck" ControlToValidate="Name" Display="Static" runat="server" ForeColor="red" 
ErrorMessage="Validation Error Message" SetFocusOnError="True" 
OnServerValidate="CheckForAccess" /> 

This ends up in HTML elements with attributes that may enable the client-side validation framework to execute.

Check For Validation Errors On Postback
Whereas validation ought to run on the client-side before the form is submitted to the server, it's still a good observe to see for errors on the server. There are variety of reasons for this, however the most reason should be that the client is an unknown quantity. There are completely different browsers, JavaScript will be disabled, developer tools enable people to change HTML and thus may result in unexpected data being denote. So, check your validation before you start process your type data on the server. And it's as simple as wrapping your server-side logic in a single code block.

MVC
[HttpPost] 
[ValidateAntiForgeryToken] 
public ActionResult Edit(ViewModel model) 

if (ModelState.IsValid()) 

    // your code to process the form 
}  
else 

    ModelState.AddModelError(String.Empty, "Meaningful Error message); 
    return View(model); 

return RedirectToAction("Index"); 


Webforms
protected void Page_Load(object sender, EventArgs e) 

if (IsPostback) 

    if (!IsValid) 
    { 
        // validation failed. Do something 
        return; 
    } 
     
    // do your form processing here because validation is valid 
}  
else  

    // non-postback 

Do one thing useful with your Validation Errors
If you discover that validation errors have gotten through to your server, you would like to capture them and show them to the user. a quick way that I even have found to try and do this is with a loop using the validator collection and look for errors. There are variety of things you will do like add the error messages to the Validation summary box at the top of your form, write to an audit log or build them seem in a dialog box.

foreach (IValidator aValidator in this.Validators) 

if (!aValidator.IsValid) 

    Response.Write("<br />" + aValidator.ErrorMessage); 



Validation is a critical part of form submission and should be used to it's full potential.

HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.

 



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in