Link to home
Start Free TrialLog in
Avatar of arthurh88
arthurh88

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of gnoon
gnoon
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>")
Avatar of arthurh88
arthurh88

ASKER

ajax...didn't even know what that was until you recommended it and I looked it up...it looks just like what I need!
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.