Welcome to EMC Consulting Blogs Sign in | Join | Help

Kalpesh Prajapati

Create and post form through Java Script to new window

Very basic Java Script which require once in awhile in the world of ASP.NET.

I came across the situation where requirement was to post form to basic ASP page from asp.net page. That can be done by using PostBackUrl property available in Button control. Now that is simple but PostBackUrl will post entire ASP.NET form and extra data will be posted.

 

Complexity in requirement was that form should be posted to asp page to new window. I tried to find a lot to post data to new window using asp.net button control and PostBackUrl property. If you find please let me know. Then I had to write Java Script.

 

Ok. Now here is code after lots of text and description.

 

//Create form

function createForm(formName, actionURL, target, method)

{

    var oForm = document.createElement("form");

    oForm.name = formName; //Form name

    oForm.id = formName; // Form ID

    oForm.action = actionURL; // URL to post back

    oForm.target = target; // This is important. Use “_blank” if you wish to post back to new window

    oForm.method = method; // Method GET or POST

    return oForm;

}

 

//Create input fields

function createInputField(name, value, type)

{

    var oField = document.createElement("input");

    oField.name = name;

    oField.id = name;

    oField.value = value;

    oField.type = type; // Type normally “hidden”

    return oField;

}

 

 

//Append Field to form

function appendField(oForm, oField)

{

    oForm.appendChild(oField);

}

 

//Here is code to create form, field and submit the form

function submitEligibilityForm(sNewFormAction, Field1Value, Field2Value)

{

    var oForm = createForm("FormName", sNewFormAction,"_blank","POST");

 

    var oField = createInputField("Field1", Field1Value,"hidden");

    appendField(oForm,oField);

 

    oField = createInputField("Field2", Field2Value,"hidden");

    appendField(oForm,oField);

 

    document.appendChild(oForm); //This is required to add form to document

 

    oForm.submit();

}

 

Here is HTML code to create and submit the form

<input tyep=”button” text=”click me” onlick=”submitToEligibilityHandoff('submitpage.asp',' Field2Value ', 'Field2Value'); return false;">

 

 

Published 25 July 2008 14:18 by kalpesh.prajapati
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Random said:

Goto : www.google.com

Search : "posting asp.net page to classic asp page"

Goto first link, You will find an answer from MS Online support with other options.

July 28, 2008 08:56
 

das said:

ADSsdaD

January 15, 2009 08:52
 

ADSFSAD said:

SAFSAFSAFSAFSAFSAFSAF

January 15, 2009 08:53
 

ee said:

dwdddwwd

January 21, 2009 14:49
 

alert(hi); said:

alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);alert(hi);

March 27, 2009 13:30
 

alert(hi); said:

<script>alert(hi);</script>

March 27, 2009 13:31
 

&lt;script&gt;alert(hi);&lt;/script&gt; said:

&lt;script&gt;alert(hi);&lt;/script&gt;

March 27, 2009 13:32
 

Aloke Saha said:

If u Want to build your career as a Plumber, please visit my site  

http://www.ableskills.co.uk/plumbing.htm

I think this Website helps u Very Much.  

May 23, 2009 05:55
 

<script>alert(123)</scirpt> said:

<script>alert(123)</scirpt>

December 12, 2010 18:25

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Personal Edition), by Telligent Systems