Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Custom DropDownLsit

Custom DropDownLsit

Scheduled Pinned Locked Moved ASP.NET
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mehran asg
    wrote on last edited by
    #1

    I created Custom dropDownList . I use it in a page. but I can't access to it in code behind.

    B A M 3 Replies Last reply
    0
    • M mehran asg

      I created Custom dropDownList . I use it in a page. but I can't access to it in code behind.

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Show your code what did you do so far.


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

      1 Reply Last reply
      0
      • M mehran asg

        I created Custom dropDownList . I use it in a page. but I can't access to it in code behind.

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        mohandesmehran wrote:

        but I can't access to it in code behind.

        what does it mean ? from where you are trying to access the code?

        cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net View My Recent Article

        1 Reply Last reply
        0
        • M mehran asg

          I created Custom dropDownList . I use it in a page. but I can't access to it in code behind.

          M Offline
          M Offline
          mehran asg
          wrote on last edited by
          #4

          namespace HakhamaneshControl { [ToolboxData("<{0}:Drp_Languages runat=server></{0}:Drp_Languages>")] public class Drp_Languages : DropDownList { protected override void RenderContents(HtmlTextWriter output) { output.RenderBeginTag(HtmlTextWriterTag.Option); output.AddAttribute(HtmlTextWriterAttribute.Value, "Ar"); output.Write("Ar"); output.RenderEndTag(); } } } /// <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CreateCustomControl._Default" %> <%@ Register Assembly="ServerControl1" Namespace="HakhamaneshControl" TagPrefix="cc2" %> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> <div> <cc2:Drp_Languages ID="hhhh" runat="server"> </cc2:Drp_Languages> </div> </form> </body> </html> //code behind protected void Button1_Click(object sender, EventArgs e) { Response.Write(DropDownList1.SelectedItem.Value.ToString());// null refrence exception }

          B 1 Reply Last reply
          0
          • M mehran asg

            namespace HakhamaneshControl { [ToolboxData("<{0}:Drp_Languages runat=server></{0}:Drp_Languages>")] public class Drp_Languages : DropDownList { protected override void RenderContents(HtmlTextWriter output) { output.RenderBeginTag(HtmlTextWriterTag.Option); output.AddAttribute(HtmlTextWriterAttribute.Value, "Ar"); output.Write("Ar"); output.RenderEndTag(); } } } /// <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CreateCustomControl._Default" %> <%@ Register Assembly="ServerControl1" Namespace="HakhamaneshControl" TagPrefix="cc2" %> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> <div> <cc2:Drp_Languages ID="hhhh" runat="server"> </cc2:Drp_Languages> </div> </form> </body> </html> //code behind protected void Button1_Click(object sender, EventArgs e) { Response.Write(DropDownList1.SelectedItem.Value.ToString());// null refrence exception }

            B Offline
            B Offline
            Blue_Boy
            wrote on last edited by
            #5

            try this way

            Response.Write(DropDownList1.SelectedValue.ToString());


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

            M 2 Replies Last reply
            0
            • B Blue_Boy

              try this way

              Response.Write(DropDownList1.SelectedValue.ToString());


              I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

              M Offline
              M Offline
              mehran asg
              wrote on last edited by
              #6

              unfortunately don't work. I think ,I must add items in a different manner. but I don't know how.

              1 Reply Last reply
              0
              • B Blue_Boy

                try this way

                Response.Write(DropDownList1.SelectedValue.ToString());


                I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

                M Offline
                M Offline
                mehran asg
                wrote on last edited by
                #7

                unfortunately don't work. I think ,I must add items in a different manner. but I don't know how.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups