Item is not being added in the dropdown list #Asp.net -
I've added a dropdown list in the webform and added two items through the Edit Item option. While debugging this page, I'm adding a new item (using a text box and a button for this) that is displayed in this drop down list, while only once I close the session And if it is opened again it is disappearing.
The code for:
.aspx page:
& asp: dropdown list id = "dropdown list 1 "runat =" server "height =" 22px "width =" 82px "& gt; & Lt; Asp: ListItem text = "Select" value = "- 1" selected = "true" & gt; & Lt; / ASP: ListItem & gt; & Lt; Asp: ListItem Text = "Item1" value = "Wrigley" & gt; & Lt; / Asp: ListItem & gt; & Lt; Asp: ListItem text = "Item2" value = "sigma" & gt; & Lt; / Asp: ListItem & gt; & Lt; / ASP: DropDownList & gt; & Lt; Asp: Button ID = "Bt_Save" runat = "server" text = "save" visible = "false" onclick = "Bt_Save_Click" /> & Lt; ASP: Text Box ID = "TBCN" Run = "Server" visible = "Wrong" width = "123px" ontextchanged = "TB_CName_TextChanged" & gt; & Lt; / Asp: text box & gt;
.aspx.cs page
Protected Zero Bt_Save_Click (Object Sender, EventArgs E) {String NewCustomer = TB_CName. Text.ToString () Trim () .; If (new customer! = "") {DropDownList1.Items.Add (new list item (new customer, new customer)); TB_CName.Text = null; DropDownList1. Person = true; Bt_Save.Visible = false; TB_CName.Visible = false; } Other {Validater_CName.Visible = true; }}
Every time I add a new item to the changed dropdown list, what do I do to please post your suggestions.
Thank you!
In the drop-down list displayed only once I close the session and again If I open it, then it is disappearing.
You remember the basic concept that the HTML state is low
The reason for this is the first time you see ASP.Net ViewState uses the state to continue between post-banks. Once you close the browser or tab (it does not matter), the state's information has gone.
To continue with the data, you need to store it in a database (or a file).
Note: You can use ASP.NET cache which is stored in server memory. However, the cache is shared by all pages, so this is not for your scenario.
Comments
Post a Comment