0

I have got a dropdown list populated with products from a product table. I have a button named ADD Product, so when the user wants to add a new product instead of selecting product from the drop down list, one should click on add new then panel 1 should show which includes a textbox. Panel1 visibility is set to false by default and it should be visible when the user clicks on the button. Also I want a validation on dropdown list and textbox(if panel is visible). Below is the code which is not working :

   <asp:DropDownList ID="DropDownList1" runat="server">
         </asp:DropDownList>
         <%--<asp:TextBox ID="txtMake" runat="server" CssClass="txtStyle"></asp:TextBox>--%>
         <asp:Button ID="btnAdd" runat="server" />
         <asp:Panel ID="panel1" Visible="false" runat="server"><asp:TextBox ID="txtAddnew"></asp:TextBox></asp:Panel>
         <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please Select a Product" ValidationGroup="insert" ControlToValidate="DropDownList1" ForeColor="Red"></asp:RequiredFieldValidator><br />

codebehind:

protected void btnAdd_Click(object sender, EventArgs e)
    {
        panel1.Visible = true;
    }
     protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            MultiView1.ActiveViewIndex = 0;
             DropDownList1.DataSource = caravans.GetProductNames();
            DropDownList1.DataBind();
        }
    }
1
  • Post your complete form design. Commented May 16, 2011 at 12:03

1 Answer 1

1

You can use this concept for validation on dropdownlist. I am given you an example please check this...

<asp:DropDownList runat="server" ID="ddl">
            <asp:ListItem Value="-1" Text="Select"></asp:ListItem>
            <asp:ListItem Value="1" Text="One"></asp:ListItem>
            <asp:ListItem Value="2" Text="Two"></asp:ListItem>
        </asp:DropDownList>
        <asp:RegularExpressionValidator ID="reg1" runat="server" ControlToValidate="ddl"
            Display="Dynamic" ErrorMessage="Select Proper" SetFocusOnError="true" Text="Select Proper"
            ValidationGroup="check" ValidationExpression="^\d{0,5}$" />
        <asp:Button ID="btn" runat="server" ValidationGroup="check" Text="Submit" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.