Refer the below link and chage as per your requirement.
Else you have to do like below.
HTML
<div>
<asp:Button Text="New CID" runat="server" OnClick="NewCid" />
<br />
<asp:Label ID="lblnewCId" runat="server" />
</div>
Code
C#
protected void NewCid(object sender, EventArgs e)
{
lblnewCId.Text = GenrateNewCId();
}
private string GenrateNewCId()
{
string newCId = string.Empty;
if (Session["CID"] == null)
{
Session["CID"] = DateTime.Now.ToString("yyMM") + "0000";
newCId = Session["CID"].ToString();
}
else
{
string cId = Session["CID"].ToString();
int previousCId = int.Parse(cId.Substring(4));
previousCId++;
newCId = DateTime.Now.ToString("yyMM") + (previousCId).ToString().PadLeft(4, '0');
Session["CID"] = newCId;
}
return newCId;
}
VB.Net
Protected Sub NewCid(ByVal sender As Object, ByVal e As EventArgs)
lblnewCId.Text = GenrateNewCId()
End Sub
Private Function GenrateNewCId() As String
Dim newCId As String = String.Empty
If Session("CID") Is Nothing Then
Session("CID") = DateTime.Now.ToString("yyMM") & "0000"
newCId = Session("CID").ToString()
Else
Dim cId As String = Session("CID").ToString()
Dim previousCId As Integer = Integer.Parse(cId.Substring(4))
previousCId += 1
newCId = DateTime.Now.ToString("yyMM") & (previousCId).ToString().PadLeft(4, "0"c)
Session("CID") = newCId
End If
Return newCId
End Function
Screenshot