?
Solved

asp.net user control

Posted on 2005-04-14
2
Medium Priority
?
258 Views
Last Modified: 2010-04-07


Suppose my asp.net application is designed such that I create several user controls.

Lets say I have some user control,   PaymentMethodUserControl which I drag and drop into my startup form.

How do I reference the elements of PaymentMethodUserControl1 within the context of the startup form?

for example, I would like to do something like this within the context of the startup form (the form in which I dragged the user control):
if Me.PaymentMethodUserControl1.radioButtonCash.checked = true then....  [this logic could, for example, be in the click event of some button within the startup form]

Of course, the above does not work (not even if you change the code of PaymentMethodUserControl, such that all the radio buttons are made public instead of protected).

I get the following error:
Object reference not set to an instance of an object (PaymentMethodUserControl1).

0
Comment
Question by:kamleshmistry
2 Comments
 
LVL 28

Assisted Solution

by:rafrancisco
rafrancisco earned 780 total points
ID: 13786529
Try:

((RadioButton)Me.PaymentMethodUserControl1.FindControl("radioButtonCash")).checked
0
 
LVL 18

Accepted Solution

by:
tusharashah earned 1200 total points
ID: 13786777
Check 3 methods that you can use to pass values between ASPX and ASCX pages:
  http://www.c-sharpcorner.com/Code/2005/Jan/PassingValuesfrmUCtoASPX.asp

[for detail refere Link]
1) Using Properties
If the test.ascx control has two textboxes and submit button.You can access the values of the textboxes in the control from an .aspx page by declaring public property in the .ascx page.

public string FirstName
{
get{return txtFirstName.Text;}
set{txtFirstName.Text = value;}
}

2) Using Javascript

You can set the values of the controls declared in the .ascx page by

document.forms[0]['TestControl:txtFirstName'].value ="Suzzanne";

You can get the values of the controls declared in the .ascx page by

document.forms[0]['TestControl:txtFirstName'].value

3) In ASPX code behind file

TestControl objTestControl = (TestControl)Page.FindControl("TestControl");
TextBox objTextBox = objTestControl.FindControl("txtFirstName");
string strFirstName = objTextBox.Text;

-tushar
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Integration Management Part 2
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question