简体   繁体   中英

Ajax control for a drop down list to bring up user input forms?

I'm a newb on my first practice project using asp.net and c#; I need to display an input form on my "Add Product" page, and have it send the user info to the database, then on buttonclick postback and display the data in read-only format. I'd like to use ajax for this, and I'm thinking that it would be best to use an update panel for each of the products, and on buttonclick, I'll use a switch case statement to display the respective forms. I've never used switch-case before, and I'm wondering what method I could use to display the forms. For example,

Switch (DropDownList1.SelectedValue)
     {
         case 0:
         //what method would display the update panel for this product?
         break;
         case 1:
         //etc.
         default:
         error message;
         break;
      }

One solution would be that you don't use a postback and then call a web method via javascript and that would send your data to the database.

The process that I would use is:

  1. Put input tag and html button the page.
  2. Create a web method within a new web service.
  3. Create a javascript method for calling this web method a. using script manager tag and service reference to your web service b. or using jquery ajax call to the web service
  4. Modify the javascript to make the form readonly
  5. Tie the button to the javascript function onclick

Here's what I ended up using. I put the forms in panels, set them as invisible, and then ran the visible=true method on the selected values from the ddl, and then ran a remove.selecteditem method on the ddl event to avoid redundant products.

protected void BtnAddProduct_Click(object sender, EventArgs e)
{
    switch (DdlProductList.SelectedValue)
    {
        case "1":
            PanelEpl.Visible = true;
            break;
        case "2":
            PanelProf.Visible = true;
            break;
        case "3":
            PanelCrime.Visible = true;
            break;
        case "4":
            PanelFid.Visible = true;
            break;
        case "5":
            PanelNotProf.Visible = true;
            break;
        case "6":
            PanelPriv.Visible = true;
            break;
        case "7":
            PanelPub.Visible = true;
            break;
        default:

            break;
    }
}

 protected void DdlProductList_SelectedIndexChanged(object sender, EventArgs e)
{
    DdlProductList.Items.Remove(DdlProductList.SelectedItem);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM