This question is an exact duplicate of:

protected void Page_Load(object sender, EventArgs e)
{
    TextBox1.Text = Request.Form["tbContractNo"];  
    TextBox2.Text = (TextBox1.Text).Length.ToString();
}
    protected void Button1_Click(object sender, EventArgs e)
{        
    string result = "";
    result = (TextBox1.Text).Substring(4, 1);

try
    {

    }
    catch
    {
    }
    finally
    {

        if (result == "H")
        {
            HiddenField2.Value = TextBox1.Text ; 
            Server.Transfer("~/LtssEnrollment-HCS.aspx", true);
        }
        else
        {
            if (result == "I")
            {
                Server.Transfer("~/LtssEnrollment-ICF.aspx", true);
            }
        }
    }
}

Textbox1 shows "0000H07C7". Textbox2 show 9 - the number of digits. Get startIndex cannot be larger than length of string.

  Parameter name: startIndex

 Source Error: 


Line 43:         //string alpha2 = alpha.ToString();
Line 44:         string result = "";  
Line 45:         result = (TextBox1.Text).Substring(4, 1);  
Line 46: 
Line 47:     try

Stack Trace: 

What is going on? Is the value of TextBox1 losing its value on button click??

Related posts

Recent Viewed