Last active
February 1, 2017 07:16
-
-
Save Phuseos/94fd32f10bbaf9a94650aab63c1b78a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void TextBoxNullCatcher(object sender, EventArgs e) | |
{//Code to makes sure all controls that are textboxes have at least a '1' value. | |
if (sender is Control) | |
{ | |
var usedControl = sender as Control; //Declare the control | |
if (usedControl is TextBox) | |
{ | |
TextBox txtType = usedControl as TextBox; //Set the control as a textbox | |
if (string.IsNullOrEmpty(Convert.ToString(txtType.Text))) | |
{ | |
txtType.Text = Convert.ToString("1"); | |
/* | |
You can shorten it like this: | |
txtType.Text = string.IsNullOrEmpty(txtType.Text) ? "1" : txtType.Text; | |
Or txtType.Text = txtType.Text ?? "1"; | |
*/ | |
} | |
} | |
} | |
//Rest of your code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment