0

This is going to be easy for someone who knows what they are doing.

I have a launch calendar button, a continue button, and a date textbox. The button launches a JavaScript calendar in a popup window. That calendar returns a date into the ReservationDate textbox field using:

window.opener.document.getElementById('ctl00_wpm_ShowProduct_ctl10_ReservationDate').value = '<%= CurrentDate %>';

I know, it's not elegant but works. The problem is that even though on the browser I see the date in the field, when I hit the continue button and try to access it from my .NET script, the server side script sees it as empty.

How do I tell the server to use the text the browser has in that field that it is not seeing?

I know enough to know that it's a server side versus client side issue but how do I bridge that gap?

5
  • Do you have any other code hat may be overwriting that value earlier in the page lifecycle? Commented Apr 26, 2011 at 15:40
  • If you're able to see the text in the field before you submit the postback, then I think something is probably wrong in your code behind. You're probably not checking IsPostBack Can you post that code as well? Commented Apr 26, 2011 at 15:41
  • @Chad, than he wouldn't be able to compile He sees it as empty, not as inexisting Commented Apr 26, 2011 at 15:42
  • Yeah i put that together when i reread and looked at the control name. Commented Apr 26, 2011 at 15:44
  • it would be a good idea to post your html, and server side script too. do you have runat="server" in the textbox declaration? when you try to access the textbox, is it found on the server? Commented Apr 26, 2011 at 15:46

2 Answers 2

3

I think you have set your textbox as ReadOnly and that seems to be an issue. Set it readonly like this in code behind:

TextBox1.Attributes.Add("readonly", "readonly");

Check this.

Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant gbs! It threw me off that I could see the value onscreen and never considered readonly. Thank you for solving a problem that's making me crazy this week... I'm sure there will be a new one next week. :)
1

If you initialize the value in the Page_Load, the value will get lost. I guess it must be something like that.

So you would write in your Page_Load:

if(!Page.IsPostBack)
{
Initialize();
}

1 Comment

I would be willing to bet that this is the problem. Hard to tell without seeing the code though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.