Updating Textbox Server Control with Javascript

Good evening Experts:

I am having some difficulties updating an asp textbox server control with a Javascript routine.  In my situation, the user has the ability to populate two textboxes with a Javascript calendar control [BeginDt and EndDt].  This part works fine --  the user selects the date and the textbox control is populated; however, when the webform is submitted, the dates selected using the Javascript routine are not being reflected after the postback.      For example, if the BeginDt control displays 02/01/2008, and the user selects 02/03/2008 from the calendar control, the BeginDt textbox will display the change, but when the form is submitted, and the postback is complete, the original value [02/01/2008] is displayed.

When I debug the application and step through the code, the value in BeginDt.Text and EndDt.Text are displaying the original value prior to updating them with the Javascript control.

I am using VB.NET 2008 ..  Any help would be appreciated.
clsCampaign.CommunityNumber = CommunityNumber.Value
clsCampaign.CampaignName = CampaignName.Text
clsCampaign.CampaignDescription = CampaignDescription.Text
clsCampaign.Sort = Sort.Text
clsCampaign.EndDT = EndDt.Text   <-- Displaying original value 
clsCampaign.BeginDT = BeginDt.Text   <-- Displaying original value

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you populating the textbox with a default value in page_load or something similar? Make sure any default value population code is wrapped in a If not page.IsPostBack then ... block otherwise the textbox values will be reset back before any control events fire.
escheiderAuthor Commented:

Yes, the private sub that is being referenced in the page_load event is encapsulated within a ispostback conditional:

If Not IsPostBack Then
            If Len(Trim(clsCampaign.CampaignID)) > 0 Then
                DataToFormBind()  <-- populate form objects here
            End If
End If
Private Sub DataToFormBind()
        CampaignName.Text = clsCampaign.CampaignName
        CampaignDescription.Text = clsCampaign.CampaignDescription
        BeginDt.Text = clsCampaign.BeginDT
        EndDt.Text = clsCampaign.EndDT
        Sort.Text = clsCampaign.Sort
End Sub

Open in new window

That looks ok, any other code you can post? I'm sure it must be something code related, we use a javascript based calendar, the textbox doesn't care how the text gets there, if it's there it should be in the form collection.
As a test you could change
clsCampaign.EndDT = EndDt.Text to
clsCampaign.EndDT = request.form("EndDt") (assuming your textboxes are just on the page, not in usercontrols or anything) to make sure the correct value is being posted back. If this fixes the problem you know the value is being overwritten somewhere in your asp.net code, if it doesn't the problem is possibly in your client side script somewhere.
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

escheiderAuthor Commented:
I changed it to request the form object values and that worked ..   I'm not sure where to check now.
escheiderAuthor Commented:
Interesting ..  the two textboxes where defined as read-only.  When I set that attribute to false, it works fine.  Can the value not be updated by client-side script if the control is set to read-only?
I suspect this is probably the case, same thing happened when I tested it. If you want your textboxes to be read-only then you could always put a hidden field on the page, have the javascript update that at the same time and get the value from there.
Other than that there's nothing particularly wrong with using the form values directly.
Thinking about it, probably a better solution is taking our the readonly = true from the server tag and in your page load or prerender put EndDt.Attributes("readonly") = "readonly"
This will set the client side readonly property but won't affect the server side processing so you should see the changes reflected in EndDt.text

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
escheiderAuthor Commented:
Thanks for the input ..  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.