Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


User contorol does not return values

Posted on 2005-03-15
Medium Priority
Last Modified: 2010-04-16
Hi ,

I have a user control which has a drop down menu and a text box ... I have been  trying to get the values I select in the drop down menu and the text i type in  the text box in the parent form (WebForm1.aspx) . I have delclared  two property in the ascx page

                               public string zipcode
                  get{return TextBox1.Text.ToString();}
            public  string SLocation
                  get{return DropDownList1.SelectedValue.ToString(); }
I zipcode is the value i would be reurning from the text box and Slocation would the value I would be returning frm the drop down menu.

In Webform1.aspx I have delcared

protected  projectNamespce.UserControlclass  c;

I have dragged and dropped the user control in the aspx page
I hve a button on the Webform1.aspx
When i run the project .... I get the user control wich contains the dropdown menu and the text box and a button which I added to the aspx page...

I select the dropdown and type some thning in the text box ... and on click on the button .... I have just written
private void Button1_Click(object sender, System.EventArgs e)

but i get an error message sayin ...object refrence not set .... I have no idea as to whats happening here ..

any help is greatly appreciated

Question by:Ashwin_shastry
LVL 18

Expert Comment

ID: 13550590
make sure that you declare your user control in aspx page with id="c"
LVL 13

Expert Comment

ID: 13550965
You must declare user control with the same ID. If you dragged and dropped the user control in the aspx page, then the ID should be UserControl1, you can alter the ID by goto property bag or switch to HTML code and change ID of user control to "c" like you want

Accepted Solution

pramodsk5 earned 800 total points
ID: 13555452
This will help you.


DropDownlistuc1 is the usercontrol and dropdownlist1 is the id .

It works fine.

Author Comment

ID: 13556753
thanks pramodsk .....


actually it is ...

DropDownlistuc1 = ID
DropDownList1 = the name of the dropdown in the ascx page

Thanks for the quick response for others too .....


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Loops Section Overview
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

578 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