Setting dynamic Text Box after post backs
-
Hello everyone. It's me again, and on my project teh user is suppose to press a button, and then when the post back occurs I check what the user entered in in the dynamic text box, and if it is less than a certain number it should put a different number that is valid in. Let's say the user enters in 10, but the minimum number to enter in is 15, it should put that number in the text box. I tried Request.Form.Set() but that is apparently read-only so that did not work. Thanks. Sincerely, The Major Rager
-
Hello everyone. It's me again, and on my project teh user is suppose to press a button, and then when the post back occurs I check what the user entered in in the dynamic text box, and if it is less than a certain number it should put a different number that is valid in. Let's say the user enters in 10, but the minimum number to enter in is 15, it should put that number in the text box. I tried Request.Form.Set() but that is apparently read-only so that did not work. Thanks. Sincerely, The Major Rager
Are you having trouble checking the value? If so, use the RangeValidator class, you can set the control for it to validate, maximum value and minimum value. If the value of the text box is outside the range, you can set the value of the text box to the minimum. I would do this in the page_load section in an if block "if (Page.IsPostBack)" ex if ( Page.IsPostBack ) { rangevalidator.ControlToValidate = "textbox1"; rangevalidator.MaximumValue = "100"; rangevalidator.MinimumValue = "15"; if ( rangevalidator.IsValid ) { // do your thing } else { textbox1.Text = "15"; rangevalidator.ErrorMessage = "whatever you want to tell the user"; } }
-
Are you having trouble checking the value? If so, use the RangeValidator class, you can set the control for it to validate, maximum value and minimum value. If the value of the text box is outside the range, you can set the value of the text box to the minimum. I would do this in the page_load section in an if block "if (Page.IsPostBack)" ex if ( Page.IsPostBack ) { rangevalidator.ControlToValidate = "textbox1"; rangevalidator.MaximumValue = "100"; rangevalidator.MinimumValue = "15"; if ( rangevalidator.IsValid ) { // do your thing } else { textbox1.Text = "15"; rangevalidator.ErrorMessage = "whatever you want to tell the user"; } }
Hi, thanks for replying to my message. I actually used this
((TextBox)(Page.FindControl(identity)));
where identity was the name of the text box and I was able to get and cast the control as a text box and then manipulate the data in it. Thanks a lot for replying however! Sincerely, The Major Rager