Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Monday, June 22, 2020

How to calculate work days except Saturday and Sunday

Script shows the complete definition for a user defined function that calculates working days by mostly using the DATEDIFF function.

CREATE FUNCTION [dbo].[fn_GetTotalWorkingDays]
(
    @DateFrom Date,
    @DateTo Date
)
RETURNS INT
AS
BEGIN
    DECLARE @TotDays INT= DATEDIFF(DAY, @DateFrom, @DateTo) + 1;
    DECLARE @TotWeeks INT= DATEDIFF(WEEK, @DateFrom, @DateTo) * 2;
    DECLARE @IsSunday INT= CASE
WHEN DATENAME(WEEKDAY, @DateFrom) = 'Sunday'
THEN 1
ELSE 0
  END;
    DECLARE @IsSaturday INT= CASE
   WHEN DATENAME(WEEKDAY, @DateTo) = 'Saturday'
   THEN 1
   ELSE 0
    END;
    DECLARE @TotWorkingDays INT= @TotDays - @TotWeeks - @IsSunday + @IsSaturday;
    RETURN @TotWorkingDays;
END
 
Example :




Wednesday, June 17, 2020

DateDiff to output hours and minutes

Very simply:

CONVERT(TIME,Date2 - Date1)

For example:

Declare @Date2 DATETIME = '2016-01-01 10:01:10.022'
Declare @Date1 DATETIME = '2016-01-01 10:00:00.000'
Select CONVERT(TIME,@Date2 - @Date1) as ElapsedTime

Yelds:

ElapsedTime
----------------
00:01:10.0233333

(1 row(s) affected)

Tuesday, June 16, 2020

Get value of ReadOnly TextBox in ASP.Net and retain its value across PostBack

Here Sandeep Kumar Rauniyar has explained how to get the value of ReadOnly TextBox on PostBack and also how to retain its value across PostBacks.

In this article I will explain how to get the value of ReadOnly TextBox on PostBack and also how to retain its value across PostBacks.

 A common example is when working with Calendar Control, when date is selected the value is set client side and if the TextBox is set as ReadOnly the selected date value is lost and the updated value is not available in the TextBox Text property on PostBack.


Issue
Whenever for the ASP.Net Textbox if the ReadOnly property of the Textbox is set to true, the selected data is not available in the Text property of the Textbox on PostBack as shown in the screenshot below.
 



Reason
 
The reason behind this issue is that whenever value of an ASP.Net Textbox is set to ReadOnly and the value of the textbox is set client side using client side script like JavaScript, in such cases the value of the Textbox is not available in the Text property of the ASP.Net Textbox. The ASP.Net AJAX Control Toolkit CalendarExtender makes use of JavaScript to set the selected date in the Textbox.
 
Solution
 
The solution to the issue is making use of Request.Form collection. As this collection has values of all fields that are posted back to the server and also it has the values that are set using client side scripts like JavaScript.
 
Thus we need to do a small change in the way we are fetching the value server side.
 
C#
 
protected void Submit(object sender, EventArgs e)
{
    string date = Request.Form[txtDate.UniqueID];
}
 
VB.Net
 
Protected Sub Submit(ByVal sender As ObjectByVal e As System.EventArgs)
    Dim strDate As String = Request.Form(txtDate.UniqueID)
End Sub
 
As you can see above I am fetching the value of the Textbox from the Request.Form collection using the UniqueID property of the Textbox which is nothing but Client Side name of the ASP.Net TextBox control
The screenshot below describes that the selected date value is now available server side when fetched using the Request.Form collection
 




Thursday, June 4, 2020

Set MaxLength property to Multiline Textbox

It is so easy to limit the number of characters allowed in a normal textbox by using MaxLength property, But same doesn’t work if the TextMode property of textbox is set to Multiline.

By default TextMode = "SingleLine" for a normal textbox, and it gets rendered as an input type textbox and when we set its TextMode property to MultiLine, it gets rendered as a textarea.

code

Note: MaxLength property works only for input type and not for textarea. So to handle this, either you can use JavaScript, jQuery or any other scripts. But in this article I used C# to handle this.

So let's take an example, and take one normal textbox and one multiline textbox and see differences before and after writing codebehind.

.aspx:

  1. <asp:TextBox ID="txtMultiLine" runat="server" TextMode="MultiLine" MaxLength="5"></asp:TextBox>    
  2.         <br />    
  3.  <asp:TextBox ID="txtNormal" runat="server" MaxLength="5"></asp:TextBox>    
CodeBehind:
  1. using System;    
  2. using System.Web.UI;    
  3.     
  4. namespace Maxlength    
  5. {    
  6.     public partial class MacLength : System.Web.UI.Page    
  7.     {    
  8.         protected void Page_Load(object sender, EventArgs e)    
  9.         {    
  10.             if (!Page.IsPostBack)    
  11.             {    
  12.                 txtMultiLine.Attributes.Add("maxlength", txtMultiLine.MaxLength.ToString());    
  13.             }    
  14.         }    
  15.     }    
  16. }  
I hope you enjoyed it. Please provide your valuable suggestions and feedback.

Monday, September 11, 2017

How to fixed an error message invalid value for the "InputManifest" parameter of the "GenerateApplicationManifest" task in visual studio

Hello everyone! In this post I would like to share how to fixed an error message invalid value for the "InputManifest" parameter of the "GenerateApplicationManifest" task in visual studio. The full error message as:
"obj/x86/Debug/namespace.exe.manifes" is an invalid value for the "InputManifest" parameter of the "GenerateApplicationManifest" task. Multiple items cannot be passed into a parameter of type "Microsoft.Build.Framework.ITaskItem".


An error  message invalid value for the "InputManifes" parameter of the "GenerateApplicationManifest" task
To fixed this problem, please follow a few steps below:
1. First, right click on project namespace in Solution Explorer panel and then choose properties

 or go to menu bar--> click on Project --> click on your project namespace properties...

2.  Go to Security Tab and then  uncheck  on Enable ClickOnce security settings

Done....now your problem is solved....enjoy it :