how to pass ddl1.selectedvalue from a content page to a User Control page ( ascx page)

 Hi All,

I have a DropDownList in a content page. i would like to access its selectedvalue my user control page. the below is DDL

<asp:dropdownlist id="ddl1" runat="server" autopostback="true">
            <asp:listitem value="6" >6</asp:listitem>
            <asp:listitem value="12" >12</asp:listitem>
            <asp:listitem value="24">24</asp:listitem>
            <asp:listitem value="48">48</asp:listitem>
            <asp:listitem value="999">All</asp:listitem>
        </asp:dropdownlist>

how can i access the ddl1.selectedvalue to my ascx page. i was hoping to do something like

 

public int contentDDL
{
get { return Convert.ToInt32( // what should i put here to access the ddl1.selectedvalue); }

set
{
this.Convert.ToInt32( // and here) = value;
}
}
 Thanks and i appreciate it
0
newtoaspnet2008
11/17/2008 3:00:40 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

7 Replies
1211 Views

Similar Articles

[PageSpeed] 41
Get it on Google Play
Get it on Apple App Store

public int contentDDL
{
get {
        DropDownList control = (DropDownList) this.Page.FindControl("DropDownList1");
return
Convert.ToInt32( control.SelectedValue); }

set
{
this.Convert.ToInt32( // and here) = value;
}
}

 

0
s10n
11/17/2008 5:03:20 AM

 Hi,

i changed it to above and i got this error.

public int contentDDL
    {
       get {

        DropDownList dd1control = (DropDownList) this.Page.FindControl("ddl1");
         return Convert.ToInt32(dd1control.SelectedValue);
       }
    
        set
        {
            this.Convert.ToInt32(dd1control.SelectedValue); ------------ getting error over here
        }
    } 

and the error i am getting is

 Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0117: 'mycontrol' does not contain a definition for 'Convert'

Source Error:

 

Line 71:         set
Line 72:         {
Line 73:             this.Convert.ToInt32(dd1control.SelectedValue);
Line 74:         }
Line 75:     }
 

Thanks i appreciate it.

 

 

0
newtoaspnet2008
11/17/2008 2:27:20 PM

Hi,

 change this:

this.Convert.ToInt32(dd1control.SelectedValue);

to this:

Convert.ToInt32(dd1control.SelectedValue);

Regards,


Segundo Serrano P.
Ing. Sistemas
http://www.4workgroup.com/
Blog: http://dotnet-peru.blogspot.com
0
Segundo
11/17/2008 2:35:21 PM

 Hi,

now i am getting this error after changing to Convert.ToInt32(dd1control.SelectedValue);

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'dd1control' does not exist in the current context

Source Error:

 

Line 72:         set
Line 73:         {
Line 74:             Convert.ToInt32(dd1control.SelectedValue);
Line 75:         }
Line 76:     } 

 

any advice sir

Thanks

 

0
newtoaspnet2008
11/17/2008 2:52:40 PM

Hi,

Summarize:

1.- the dropdownlist is in your page...right?

2.- the user control needs get the value of the dropdownlist... right?

------------------------------------------------------------------------------------------------

//in the user control:

private static int _contentDDL;

public static int contentDDL
    {
       get { return _contentDDL; }
    
        set
        {
            _contentDDL = value;
        }
    }

// from you page

MyUserControl.contentDDL = Convert.Toint32(DropDownList1.SelectedValue);

--------------------------------------------------------------------------------------

After that, yo already will have the value of the dropdownlist in the var _contentDDL.

Regards,

 


Segundo Serrano P.
Ing. Sistemas
http://www.4workgroup.com/
Blog: http://dotnet-peru.blogspot.com
0
Segundo
11/17/2008 3:12:19 PM

 Hi Sir,

Thanks that solved it but have one more question sir, now how can i access a particular item selected value. what i mean is

i have this ddl in content page 

<asp:dropdownlist id="ddl1" runat="server" autopostback="true">
            <asp:listitem value="6" >6</asp:listitem>
            <asp:listitem value="12" >12</asp:listitem>
            <asp:listitem value="24">24</asp:listitem>
            <asp:listitem value="48">48</asp:listitem>
            <asp:listitem value="999">All</asp:listitem>
        </asp:dropdownlist>

now how can i access just the value for  <asp:listitem value="999">All</asp:listitem> in my user control page on click of a button. i know selectedvalue will give me what ever i select, but i just want to access just only a particular listitem on a clikck of buttom. hope i am clear in explaining because i can be confusing at times Stick out tongue

Thanks i appreciate it

 

 

0
newtoaspnet2008
11/17/2008 4:24:04 PM

Hi,

Based on my understanding, you want to pass a specified item value on the page to the user control.

We can fulfull the task by using the following method according to Sequndo's solution:

MyUserControl.contentDDL = Convert.Toint32(ddl1.Items[4].Value);

Have a nice day! 


Forward Sun
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Forward
11/20/2008 11:21:06 AM
Reply:

Similar Artilces:

convertion from page to content page or from user control to content page
Hi, I have converted an asp.net 1.1 application to 2.0.  Now what I am looking for some enhancement.  I added a master page and now I want to add other pages as content pages. but those pages which I am converting into content have some user control. Now either I can convert those user control to content pages ( which i want to look for if it is possible),  Or I am thinking i shouldn't convert those user control to content pages cause they might be just good. So looking for some of those people opinion who have worked through this so can I get opinion here please.thanks&nb...

Passing Variable from Content Page to Web User Control embedded in a Master Page
Hi there,I have a content page (mypictures.aspx). I have a Master Page with the following code:<%@ Register TagPrefix="ECC" TagName="LeftNav" Src="leftnav.ascx" %>......................... <ECC:LeftNav ID="LeftNav1" Section="Sales" SubSection="" TertiarySection="" runat="server"/>................................  I have the LeftNav - Web User Control (leftnav.ascx). Question:Depending on the content page i am viewing (i.e. mypictures.aspx), I want to change a graphic file in leftnav.ascx file which is embedded or called by the Master Page.I am pretty novi...

Paging Paging Paging
I am trying to do paging with my search results and it isnt working very well. Here is what I've tried and I feel I've tried everything, lol, please help me out. Sub DataGrid1_SortCommand(Sender as object, e as DataGridSortCOmmandEventArgs) DataGrid1.DataBind() End Sub Sub Datagrid1_PageIndexChanged(Sender as object, e as DataGridPageChangedEventArgs) Dim ds as dataSet DataGrid1.CurrentPageIndex = e.NewPageIndex if Session("Search") is nothing then 'Session probably has expired, get the datasource from database Datagrid1.DataSource = ...

Single page with multiple user web controls VS Multiple page with specific user web controls
I have a question regarding single page with multiple user web controls vs multiple page with specific user web controls   Option 1: I am of the opinion to have multiple pages with specific user web controls and use an object to store all the information as the user navigates through the application. And finally at the end, read this object and save all the information to the backend database.   Option 2: My respected team member suggests that we have only one page, with all the specific user web controls and not use an object, instead show/hide the user web controls based ...

Passing values from content page to user control on master page
I have a content page that pulls the info for a product. Surrounding this is a master page that has some user controls on it that show content that is specific to the data being pulled in the content page. I already have the content page setting properties on the master page in the code behind, and then the master pages code behind feeding the user controls - all seems to work but seems a tad inefficient in some cases - fine when I need to go back to the databse to fetch more related records, but this particular issue shouldn't need to do that.  My content page initiates a Product cla...

How to pass the form contents of aspx page in .Net to Jsp page
Hi,   I want to pass the login information from aspx page to jsp page. plz help me how to do it. Please reply asap. Thanks...

Content controls have to be top-level controls in a content page or a nested master page that references a master page.
Why in the world am I getting this error? The solutions I have seen either don't apply or don't work.  Here is my master page code:<%@ Master Language="C#" AutoEventWireup="false" CodeFile="TechLMSMasters/MainSide.master.cs" Inherits="MainSide" %> <%@ Register TagPrefix="usercontrol" TagName="Search" Src="~/library/uc/Search.ascx" %> <%@ Register TagPrefix="usercontrol" TagName="UserName" Src="~/library/uc/UserNameDisplay.ascx" %><!DOCTYPE html PUBLI...

A page can have only one server-side Form tag
I have a web user control in my web page.  The user control (ascx) consist of a text box and button. The web page consist of text boxes and buttons also.  Both pages have form tags with runat=server.  When I run the web page it comes up with the error "A page can have only one server-side Form tag." Both the user control and web page need the form tag with runat=server.  Is there a way I can code these pages where there won't be a conflict between the web user control and the web page? Thanks   JohnMo wrote:Both the user control and web page need the form tag wit...

Error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.
when I make a directory on my root, and in that directory I put a masterpage and a web form ... I get always an error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.   Does somebody know what the problem is ? Is it possible you can't set a masterpage in a directory ... ?Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) i've founded ... I had to nest my masterpage ...Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) Hi Joeri Pansaerts, I am receiving the same error as the one posted her...

ERROR Content controls have to be top-level controls in a content page or a nested master page that references a master page.
This all used to work until about 5 minutes ago. Did I change something? For some reason I am now getting this error: Content controls have to be top-level controls in a content page or a nested master page that references a master page. What I have:  I have a masterpage inside of a directory. That directory is a first level directory with its own web.config file....The whole thing is protected by the web.config file above it (in the main public directory). That main public directory has a masterpage as well. I am not currently linking the two masterpages together becuase...

passing querystring from user control to master page's content page
Hi all,        I have a master page which contains two linkbuttons. I want that when user clicks first link button then querystring value is passed to content page's Initialize culture method. how can i do this. English | Spanish < - user control link Master page contains this user control Default page's initializeCulture method need to know which link is clicked and then set culture according.  code inside initializeculute is like thisif (Request.QueryString["Culture"] == null) {Culture = "en-US"; } else {Culture =...

Master Page , User Control,Content page
 Hi friend ,I have user control at master page, I want to access it's property using content page I have done code but getting problem in deployment.((ASP.usercontrols_travel_hotel_directory_ascx)Master.FindControl("ucHotel_Directory")).Visible = false;  But I am getting following error in deployment project Error    137    The type or namespace name 'usercontrols_travel_animation_ascx' does not exist in the namespace 'ASP' (are you missing an assembly reference?)    d:\By Shakti5385\EternalMewar\Eterna...

How to pass textbox control value from UserControl page(ascx) to Page Control(aspx).
I have 2 files(aspx and ascx). the aspx page  has a Web user control(ascx) in it.Once the button control click(in aspx) I want to get the value from the textbox(ascx) controland pass it to label control in aspx page.Can somebody help with this and please use VB.Thanks A simple search would have turn up many different solutions.  The easiest is to just expose the textbox value as a property in your control.  Then you can retrieve that value on the aspx page. Add this to your control: Public Property TextBoxValue() As String   Get   &...

Can my web page with a form submit to other web pages forms?
I was wondering if I created an aspx page that had a form on it that I could use the submit button to submit this form's contents to other web pages forms(servers accepting those form's data). I am thinking this would be a great way to update data on particular web pages without having to actually visit those similar web pages. Any ideas, examples would be much appreciated. Thanks in advance.  Yes you can.  It's called Cross Page Posting: http://msdn2.microsoft.com/en-us/library/ms178139.aspxAlso: http://msdn2.microsoft.com/en-us/library/ms178140.aspx might ...

Web resources about - how to pass ddl1.selectedvalue from a content page to a User Control page ( ascx page) - asp.net.web-forms

User Anna Lear - Stack Overflow
current community chat blog Stack Overflow Meta Stack Overflow Stack Overflow Careers your communities Sign up or log in to customize your list. ...

Index - 2,000 Things You Should Know About WPF
Below is a list of all posts created so far for the 2,000 Things You Should Know About WPF blog. Total number of posts = 1,077 Animation #7 - ...

mark. Touch & Glow Shimmer Cream Cubes All Over Face Palette - Pearly Pink
Get a pearly glow thanks to these cubes: with a sweep of a brush, combine the shimmery shades of pink,gold, and bronze for a gorgeous-on-all-skin-tones ...

dotnet HighCharts inside UpdatePanel
Read my article about the HighCharts.net databind? A frequently question regards the possibility to get functioning a dotnet.HighCharts chart ...

Tech Off - Forums - Channel 9
Want to keep the conversation technical? This is the place. Hard hat required.

Resources last updated: 12/28/2015 3:23:52 PM