HELP! Accessing controls on a user control
-
Hi, I have a rather stupid question, hope someone can help me. I am writing a webpage in C#, in VS.NET 2003. To make things easier I used some user controls. However, my question how can I access the controls in the webpage. Let's say I have my aspx page A, and user control B that is within the aspx page A. I have a textbox in the User control B. And I want to pass the value of the textbox to another page from a Button in Aspx page A. The regular approach of Session["textboxvar"]=TextboxB.Text simply doesn't work. VS.NET 2003 is complaining "The type or namespace name 'TextboxB' could not be found." How can I access it? Many, many thanks!!!
-
Hi, I have a rather stupid question, hope someone can help me. I am writing a webpage in C#, in VS.NET 2003. To make things easier I used some user controls. However, my question how can I access the controls in the webpage. Let's say I have my aspx page A, and user control B that is within the aspx page A. I have a textbox in the User control B. And I want to pass the value of the textbox to another page from a Button in Aspx page A. The regular approach of Session["textboxvar"]=TextboxB.Text simply doesn't work. VS.NET 2003 is complaining "The type or namespace name 'TextboxB' could not be found." How can I access it? Many, many thanks!!!
First of all, don't use the session if you can avoid it. You have user controls. You can put two controls on the same page, and switch which one is visible, and then viewstate will hold the values for you. you can also pass values on the URL. TextboxB exists in the user control, so that's where you need to write the code to interact with it. You can also use delegates to get your user controls to call code in other controls or the main page.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
First of all, don't use the session if you can avoid it. You have user controls. You can put two controls on the same page, and switch which one is visible, and then viewstate will hold the values for you. you can also pass values on the URL. TextboxB exists in the user control, so that's where you need to write the code to interact with it. You can also use delegates to get your user controls to call code in other controls or the main page.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
a simple solution is write a public method in user control which returns the textbox value like
public string GettbValue(){ return this.Textbox.Text;}
and access this method in ur aspx page by using B.GettbValue() method and send it using querystring... i hope this will help you thanks, deep. :) -
a simple solution is write a public method in user control which returns the textbox value like
public string GettbValue(){ return this.Textbox.Text;}
and access this method in ur aspx page by using B.GettbValue() method and send it using querystring... i hope this will help you thanks, deep. :)May as well make this a property.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )