开发者

How to pass value from visible = false textbox?

开发者 https://www.devze.com 2023-02-24 02:02 出处:网络
I set a textbox visible = false on a textbox that just holds a value.When trying to convert that value and then in开发者_Python百科put it into a query it fails in visible=false.What is the proper way

I set a textbox visible = false on a textbox that just holds a value. When trying to convert that value and then in开发者_Python百科put 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


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)


Keep your textbox visible = ture and set its height and width to ZERO.


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 e.g. in Form_Load, then it should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号