How do I start a postback with javascript?

I'm using this code on a small popup datepicker to input the date into a textbox on my main form.

Response.Write("<script language=javascript>")
        Response.Write(("window.opener.document.forms['" _
                        + (Request.QueryString.Get("FormName").ToString + ("'].elements['" _
                        + (Request.QueryString.Get("ElementName").ToString + ("'].value='" _
                        + (date1 + "';")))))))
        Response.Write("window.close();")
        Response.Write("</script>")

The problem is that when this popup places the date in the textbox on my mainform, I want a postback to initiate.  I've set postback = true, on the textbox but for some reason it doesn't register a text change via javascript as being an actual "change" and no postback occurs.  The popup correctly inputs the date into the textbox, but without a postback.

Any ideas?
arthurh88Asked:
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.

gnoonCommented:
If you have a submit button on mainform, you can simulate click on the button using javascript to do postback after the popup was closed. By the way, button's onclick handler in code behind will be invoked.

...
Response.Write("window.close();")
Response.Write("window.opener.document.getElementById('SubmitButtonId').click();")
Response.Write("</script>")

or another way is simply submit the form to invoke page_init and page_load in code behind.

...
Response.Write("window.close();")
Response.Write("window.opener.document.forms['" _
                        +Request.QueryString("FormName")+"'].submit();")
Response.Write("</script>")
0

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
totaraCommented:
the postback should trigger on the button if its AutoPostBack property is set to true.

Otherwise, why not thinking of another approach ? you could use a normal calendar control that hides/shows on the form instead ? You could create a simple usercontrol which contains an imagebutton and a calendar control  within an asp Ajax UpdatePanel for example.

 
0
thirdCommented:
just in case you will be going to triggering the submit button suggestion, put it before closing the current window not after.


Response.Write("window.opener.document.getElementById('SubmitButtonId').click();")
Response.Write("window.close();")
Response.Write("</script>")



Response.Write("window.opener.document.forms['" _
                        +Request.QueryString("FormName")+"'].submit();")
Response.Write("window.close();")
Response.Write("</script>")
0
arthurh88Author Commented:
ajax...didn't even know what that was until you recommended it and I looked it up...it looks just like what I need!
0
totaraCommented:
As I first approach to Ajax, I would recommend you to install the ASP.NET AJAX extensions (.NET 2.0) and look at the quickstarts examples that come with them.
This is not the optimal AJAX solution (which is the raw javascript XMLHttp coding way) but is far less complicated for the beginner.
The story is as simple as adding an ASP:ScriptManager werbserver control on your page (1 per page only or 1 on the Master page) then putting all the ASP.Net controls that you want to be "ajaxed" inside an ASP:UpdatePanel werbserver control.
Those 2 controls are installed with the ASP.NET AJAX Extensions and are draggable from the ToolBox in VS2005.
0
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.