Link to home
Start Free TrialLog in
Avatar of TheJay04
TheJay04Flag for United Kingdom of Great Britain and Northern Ireland

asked on

UserControl postback

I am dynamically creating a user control and placing it into a placeholder on page_load using:

Control TheModule = LoadControl("Modules/contact.ascx");
PlaceHolder1.Controls.Add(TheModule);

My User Control contains 3 textboxes 3 labels and a submit button. What I am trying to do is to check the value of each textbox and update its corresponding label if needed dependant on its value when the submit button is clicked.

I tried to add the code to the button_click event but I am guessing because on submit of the button the control is being re-made, so I moved the code to the page_load event of the user control and wrapped it around a if(IsPostBack) clause and this halfway worked but the values are always null, I am guessing this is to do with the fact I am remaking the control on_load of the page when the submit button is clicked.

My code in the user control code behind is very simple:

            if (txtName.Text == "")
            {
                lblNameError.Visible = true;
                lblNameError.Text = "please enter your name";
            }

Can someone explain how I can retrieve the value of the textbox when the submit button is clicked.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of madhevan_pillai
madhevan_pillai
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TheJay04

ASKER

Nope, My code is pretty much the same but in C#
All what happens is that when I submit the form the page refreshes and the label is not shown.
post ur full code let me see it