Does a field exists in and ASP.NET web form?

September 18, 2017

Perty simple function. And yes, I still user ASP.NET web forms for somethings.

/// <summary>
/// Does a specfic element exists in a form
/// </summary>
/// <param name="Key">Form element to look for</param>
/// <returns>True if found</returns>
private bool formElementExists(string Key)
{
    bool formElementExists = false;
    for(int i = 0; i < Request.Form.Keys.Count; i++) {
        formElementExists = Request.Form.Keys[i].IndexOf(Key, StringComparison.InvariantCultureIgnoreCase) > -1 ? true : formElementExists;
    }
    return formElementExists;
}
Tags  |  ASP.NET  |   |  Administrator