Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi folk's



In a web page there are huge number of different controls like(textbox,radiobutton,checkbox,dropdown) nearly 100 controls.


It is a registration form three levels of registration ,that is after filling level-1
what ever the field values in a controls must be saved in a session to do that

I am giving sample code below please check it out .......



ClearInputs(Page.Controls);//calling the function which is above

C#
void ClearInputs(ControlCollection cs)//to get the text in a controls and store in a session variables
    {
        foreach (Control c in cs)
        {
            if (c is TextBox)
            {
                Session["New"] = ((TextBox)c).Text;
                lbl_savesubmit1.Text += Session["New"];
            }
        }
    }
Posted
Updated 29-Aug-12 2:17am
v2
Comments
[no name] 29-Aug-12 8:21am    
And?
AmitGajjar 29-Aug-12 8:36am    
OK , so what is your issue ?
mahesh.b.p.c 30-Aug-12 0:08am    
problem is if statement is not satisfying ,and control is not entering into if statement ...

AmitGajjar 30-Aug-12 0:11am    
Have you checked ControlCollection contains any control information ?
mahesh.b.p.c 30-Aug-12 0:14am    
i have to check it now......Thank's for reply

1 solution

C#
void ClearInputs(ControlCollection cs)//to get the text in a controls and store in a session variables
    {
        foreach (Control c in cs)
        {
            if (c is TextBox)
            {
                Session["New"+c.ID] = ((TextBox)c).Text;
                lbl_savesubmit1.Text += Session["New"+c.ID];
            }
        }
    }


You override the variable session on each loop inside your foreach. That make no sense.

Hope it helps in any way.
 
Share this answer
 
Comments
Christian Amado 29-Aug-12 14:13pm    
Thanks for downvoted :)
AmitGajjar 30-Aug-12 1:18am    
you should not thank for downvote. instead i suggest you to ask for WHY DOWNVOTE? if reason is valid then we need to accept it nicely. :)
AmitGajjar 30-Aug-12 1:18am    
Although problem is different but you point out one problem with SessionID so my 4+

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