Click here to Skip to main content
15,886,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code

C#
protected void Page_Load(object sender, EventArgs e)
        {
            //new commonds start
            //new commonds end
            if (!IsPostBack)
            {

            }
        }

        public void Form_Enable(object sender, EventArgs e)
        {

            txtFName.Enabled = false; txtMName.Enabled = false; txtLName.Enabled = false; txtUNic.Enabled = false; txtUDob.Enabled = false;
            txtUHPhone.Enabled = false; txtUCNumber.Enabled = false; txtUEmail.Enabled = false; ddlUState.Enabled = false; txtUCity.Enabled = false;
            txtUAddress.Enabled = false;
            txtUComName.Enabled = false; txtUDesignation.Enabled = false; txtWPhone.Enabled = false; txtFaxNumber.Enabled = false; txtBCity.Enabled = false; txtCAddress.Enabled = false;
            txtECName.Enabled = false; txtECMNumber.Enabled = false; txtRelationship.Enabled = false; txtRHPhone.Enabled = false; txtECMNumber.Enabled = false;

            btnSave.Enabled = false; btnDelete.Enabled = false;
        }


How i would call the Form_Enable method in Page_Load to disable the textboxs. disabling work fine if i just put the codes in if(!IsPostBack){ .... }.
Posted
Updated 2-Aug-15 21:28pm
v2
Comments
Ralf Meier 3-Aug-15 3:17am    
If you want to do the same things, started from different sources, I would create an own method, put the required code-parts in it and call this method from the different Event-methods.
I hope, that matches to your question ...
Altaful Haq 3-Aug-15 3:27am    
my question is that how would i will call the method @Ralf Meier
Altaful Haq 3-Aug-15 3:27am    
my question is that how would i will call the method @Ralf Meier
Ralf Meier 3-Aug-15 3:38am    
The reason, why I don't posted it as solution was, that I'm not quiet sure, that I well understood, what you meant.
What I described was : take all your control.enable in a seperate method (void Disable_Controls) and call it from the different Event-Methos.
But resuming your reply I'm not sure, if this was your question.
I would say, that should write something more about your issue ....

1 solution

As Ralf Meier suggested you should move your code inside a new method, say
C#
public void disable_all_txt()
{
  // all disabling stuff here
}


the call is both from Page_Load and from Form_Enable, e.g.

C#
protected void Page_Load(object sender, EventArgs e)
        {
            //new commonds start
            //new commonds end
            if (!IsPostBack)
            {
              disable_all_txt();
            }

}
 
Share this answer
 
Comments
Altaful Haq 3-Aug-15 4:32am    
Thanks i got my mistake in my Form_Disable function i was try to send args which was the problem in the coding.
CPallini 3-Aug-15 4:43am    
Yes, because you actually don't need arguments. By the way, you are welcome.
Ralf Meier 3-Aug-15 6:43am    
As I wrote ... I wasn't sure anymore that this is the solution ... (because it seemed to easy ... ;))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900