简体   繁体   中英

How to pass value from visible = false textbox?

I set a textbox visible = false on a textbox that just holds a value. When trying to convert that value and then input it into a query it fails in visible=false. What is the proper way to do this since this obviously is not it. HEre is the code that passes the two textbox values to the query.

private void cmdAddAdd_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            int interestsKey;
            interestsKey = Convert.ToInt32(interestsKeyTextBox.Text);
            InterestAdd newAdd = new InterestAdd();
            newAdd.CaseNumberKey = caseNumberKeyTextBox.Text;
            newAdd.InterestsKey = interestsKey;
            db.InterestAdds.InsertOnSubmit(newAdd);
            db.SubmitChanges();

            LoadCaseNumberInterestsKey(interestsKey, newAdd.CaseNumberKey, false, "interestAdd");

            this.interestAddDataGridView.EndEdit();
            this.interestAddDataGridView.Refresh();
        }

I set the textbox behavior to visible = false.

Thanks,

Kor

保持文本框可见= ture,并将其高度和宽度设置为零。

You can use these alternatives:

  • Make your textbox enable to false (if you don't want user to modify it)
  • Use a label and set its forecolor and backcolor same (which makes it invisible)

Because you are setting the visibility to false, the textbox is not included in the form element and therefore will never be posted. If you don't care about seeing the contents of the textbox just use a hidden input. If you want to see the contents of the textbox, but don't want it to be changed you can use the readonly attribute of the textbox and set it to true. This will post the value back to the server with the form and not allow users to alter the value in the textbox.

Are you setting the Visible = false property at design time in the property sheet of the text box, or at run time in code ??

If you set the textbox Visible=false in code for eg in Form_Load, then it should work.

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