Custom DropDownLsit
-
I created Custom dropDownList . I use it in a page. but I can't access to it in code behind.
-
I created Custom dropDownList . I use it in a page. but I can't access to it in code behind.
-
I created Custom dropDownList . I use it in a page. but I can't access to it in code behind.
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
-
I created Custom dropDownList . I use it in a page. but I can't access to it in code behind.
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 }
-
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 }
-
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.
unfortunately don't work. I think ,I must add items in a different manner. but I don't know how.
-
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.
unfortunately don't work. I think ,I must add items in a different manner. but I don't know how.