Archive for December, 2011

Reset values of all controls in form/ASP.Net page using C#

December 20, 2011 2 comments

Today i am going to blog a post which is not a rocket science , well there is no rocket science ever posted from my side 🙂

I was lying in my blanket , enjoying cozy winter using the laptop , when friend of mine asked ‘what if we need to clear the values of all controls on form to defaults’.

That was not a tough question , more then tough it’s interesting as there are many scenarios in which we need to give default values to the controls on web or form in single click.

foreach is the key loop in that.

So lets start exploring this query.

Initially a form with following controls is designed.


  • Check Box : name is chkBox
  • Radio Button : name is rbtn
  • Text Box : name is txtBox
  • Drop Down : name is cmbBox
  • Button : name is btnReset

Now requirement is to set the default values to all the controls on the form or web. Right now i am going with form.

Few controls are being used to make it more easy to understand.
Here comes the code for that on btnReset_Click

private void btnReset_Click(object sender, EventArgs e)


           foreach (Control c in this.Controls)


               switch (c.GetType().ToString())


                   case "System.Windows.Forms.TextBox":

                       ((TextBox)c).Text = string.Empty;


                   case "System.Windows.Forms.ComboBox":

                       ((ComboBox)c).SelectedIndex = 1;


                   case "System.Windows.Forms.CheckBox":

                       ((CheckBox)c).Checked = false;


                   case "System.Windows.Forms.RadioButton":

                       ((RadioButton)c).Checked = false;





I have assigned the default values in Switch statement.


In case of web page , class representing text box “System.Windows.Forms.TextBox” would have been “System.Web.UI.WebControls.TextBox”


Happy coding :).


How to Unlock ports in FireFox ?

December 12, 2011 Leave a comment


Follow the steps to make your life easier 🙂

  • Type about:config in address bar of firefox


  • Search for
  • If that is not in that , don’t worry , lets create it
  • Right click and select the following options shown in image, New –> String


  • write
  • then double click that string and enter the port number which you want to be un banned.
  • I want it to be ‘111’ as i have installed SharePoint Central Administration on that port.
  • press ok and enjoy the open port 🙂