I have an input field that is appended to the HTML in a div.
I need to have this input field bound to the ctrlmenuItems in the system but I don’t know how.
I have this function which is the one calling the object:
protected void btnSave_Click(object sender, EventArgs e){
int Id = int.Parse(Request.QueryString["edit"]);
DA.page itmToEdit = DA.page.StaticGetById(Id);
itmToEdit.title = ctrltitle.Text;
itmToEdit.menuItems = ctrlmenuItems.Text;
itmToEdit.content = ctrlcontent.Text;
itmToEdit.Update();
UpdateGUI();
pnlEditArea.Visible = false;
}
I tried using:
protected global::System.Web.UI.WebControls.TextBox ctrlmenuItems;
which just creates a null reference.
I tried calling this onInit():
TextBox ctrlmenuItems = new TextBox();
ctrlmenuItems.ID = "ctrlmenuItems";
ctrlmenuItems.Text = "Enter your name";
this.form1.Controls.Add(ctrlmenuItems);
with no luck.
The appending is done like this:
litMenu.Text += string.Format(@"<div>
<a class='button' href='?del={1}'>Slet</a>
<input name='ctrlmenuItems' type='text' id='ctrlmenuItems' value'{0}' />
</div>",
itm.menuItems,
itm.id);
I need to be able to click “save” and it passes on the value from the textField to dataAccess
but I can’t figure out how to bind this “virtual” textbox correctly.
inputtags with anameattribute will be stored in theRequest.Formarray when the page posts back.Whether you add the
TextBoxcontrol manually, or simply insert the corresponding HTML (which I would not recommend, building HTML via string concatenation makes it very easy to yield invalid HTML), you can retrieve the value when your button is clicked using the following: