Hi kankon,
Check this example. Now please take its reference and correct your code.
HTML
<asp:TextBox ID="civilid" runat="server" />
<asp:Button Text="Calculate" runat="server" OnClick="OnCalculate" />
<hr />
<asp:TextBox ID="result_civilid_Age" runat="server" />
Code
C#
protected void OnCalculate(object sender, EventArgs e)
{
if (civilid.Text.Trim().Length == 12)
{
int year = 0;
if (civilid.Text.StartsWith("3"))
{
year = Convert.ToInt32("20" + civilid.Text.Substring(1, 2));
}
else if (civilid.Text.StartsWith("2"))
{
year = Convert.ToInt32("19" + civilid.Text.Substring(1, 2));
}
int current = DateTime.Today.Year;
result_civilid_Age.Text = (current - year).ToString();
}
}
VB.Net
Protected Sub OnCalculate(ByVal sender As Object, ByVal e As EventArgs)
If civilid.Text.Trim().Length = 12 Then
Dim year As Integer = 0
If civilid.Text.StartsWith("3") Then
year = Convert.ToInt32("20" & civilid.Text.Substring(1, 2))
ElseIf civilid.Text.StartsWith("2") Then
year = Convert.ToInt32("19" & civilid.Text.Substring(1, 2))
End If
Dim current As Integer = DateTime.Today.Year
result_civilid_Age.Text = (current - year).ToString()
End If
End Sub
Screenshot