Jump to content

hi i got a variety problem in asp.net usercontrol


karthikc85

Recommended Posts

hi everybody,iam facing a variety problem with asp.net(vs 2005) using c#.i have created a user control with 2 TEXTBOXES AND 1 BUTTON ON A PAGE.when i display the usercontrol STATICALLY iam able to read the values in the textboxes into session states and insert them into database. and also iam able to debug my control.ascx file also.when i display the usercontrol DYNAMICALLY iam NOT able to read the values in the textboxes into session states and CANNOT insert them into database. and also iam NOT able to debug my control.ascx file also.can anybody explain why is this happening?thanks,karthik.

Link to comment
Share on other sites

please post all the related code. It is most likely you are adding the control outside an if statment like thisif(!ISPostBack){}if this is the case you are overwritting the submitted value before it can be entered into your database.I'll help you once I can take a look at your code :)

Link to comment
Share on other sites

please post all the related code. It is most likely you are adding the control outside an if statment like thisif(!ISPostBack){}if this is the case you are overwritting the submitted value before it can be entered into your database.I'll help you once I can take a look at your code :)
hi aspnetguy,thanks for your response.heres my code:i write THIS in a button click to just show a datagrid for 2 questions and also TO DISPLAY THE USERCONTROL WITH 2 TEXTBOXES AND A BUTTON INSIDE IT TO READ THOSE 2 ANSWERS.IN .ASCX FILE OF THE USER CONTROL I HAVE CREATED 2 SESSION STATES TO STORE THE ANSWERS FROM THE 2 TEXTBOXES.WHEN I CLICK THE BUTTON IN USERCONTROL THE WHOLE USERCONTROL JUST GOES OFF AND SESSION STATES ARE GETTING EXPIRED.in button click: Control question1 = Page.LoadControl(@"~/question1.ascx"); Panel1.Controls.Add(question1);String connectionString = @"Data Source=DT-CORP-IT-8;Initial Catalog=employee;User ID=sa;Password=sa"; String queryString = "SELECT qid,qdescr FROM question"; DataSet ds = new DataSet(); SqlConnection connection = new SqlConnection(connectionString); SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection); adapter.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind();IN THE NEXT BUTTON CLICK I WANT TO STORE THE VALUES INTO DATABASE AS THIS:string x = (string)(Session["name"]); string y = (string)(Session["age"]); insert(x, y); String connectionString = @"Data Source=DT-CORP-IT-8;Initial Catalog=employee;User ID=sa;Password=sa"; String queryString = "SELECT * FROM answer"; DataSet ds = new DataSet(); SqlConnection connection = new SqlConnection(connectionString); SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection); adapter.Fill(ds); GridView2.DataSource = ds; GridView2.DataBind(); insert function: string insert, source; source = @"Data Source=DT-CORP-IT-8;Initial Catalog=employee;User ID=sa;Password=sa"; insert = @"insert into answer values ('" + a + "')"; SqlConnection conn = new SqlConnection(source); conn.Open(); SqlCommand cmd = new SqlCommand(insert, conn); cmd.ExecuteNonQuery(); conn.Close();THIS IS MY PROBLEM PLEASE SOLVE IT.IF YOU WANT STILL ANYMORE CLARIFICATIONS YOU PLEASE ASK ME I WANT TO SOLVE THIS PROBLEM AT ANY COST.IAM READY TO CONVERSE WITH AS MANY TIMES AS POSSIBLE WITH YOU AND WANT TO CLARIFY MY DOUBT.THANKS IN ADVANCE.THANKS,KARTHIK.
Link to comment
Share on other sites

okay, your problem is you are adding it on a button click. So next button click the page is refreshed and the control is lost.Dydnamic controls are hard to manage and should be avoided unless 100% absolutely necessary.My suggestion to you is to place the control on the form and use

style="display:none"

to hide it.then on your button click use

this.RegisterStartupScript("key","<script>document.getElementById('elemId').style.display = 'block';");

to show it then on the next button click it will be availbel to you.

Link to comment
Share on other sites

okay, your problem is you are adding it on a button click. So next button click the page is refreshed and the control is lost.Dydnamic controls are hard to manage and should be avoided unless 100% absolutely necessary.My suggestion to you is to place the control on the form and use
style="display:none"

to hide it.then on your button click use

this.RegisterStartupScript("key","<script>document.getElementById('elemId').style.display = 'block';");

to show it then on the next button click it will be availbel to you.

HI ASPNETGUY,CAN YOU SUGGEST ANY OTHER ALTERNATIVE FOR THE PROBLEM?CAN YOU TELL ME HOW TO STORE THOSE TEXTBOX VALUES IN ANY OTHER WAY?I HAVE BROWSED MANY SITES ALL OF THEM ARE ADVICING TO RECREATE THE USER CONTROL AGAIN??BUT IAM NOT ABLE TO UNDERSTAND WHAT THEY MEAN?PLEASE REPLY.THANKS,KARTHIK.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...