?
Solved

User contorol does not return values

Posted on 2005-03-15
4
Medium Priority
?
211 Views
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)
            {
             Response.Write(c.SLocation);
            Response.Write(c.zipcode);
            }

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

ashwin
0
Comment
Question by:Ashwin_shastry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 18

Expert Comment

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

Expert Comment

by:dungla
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
0
 

Accepted Solution

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

((DropDownList)Page.FindControl("DropDownlistuc1:DropDownList1")).SelectedValue;

DropDownlistuc1 is the usercontrol and dropdownlist1 is the id .

It works fine.
0
 

Author Comment

by:Ashwin_shastry
ID: 13556753
thanks pramodsk .....

((DropDownList)Page.FindControl("DropDownlistuc1:DropDownList1")).SelectedValue;

actually it is ...

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



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


cheers
ashwin
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

771 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