How to create dynamic form using Javascript and Submit it in ASP.Net ?

 

Dear friends ,

sometimes you need to create dynamic form in asp.net . Let see below example to understand it more clearly.

Suppose on a  button click you want pass token value to a different  handler page then you need to write following lines

<script type="text/javascript">

function callPagePostBack(accessToken) {

var form = document.createElement("form");
            form.setAttribute("method", ‘post’);
            form.setAttribute("action", ‘LoginAuthentication.ashx’);

            var field = document.createElement("input");
            field.setAttribute("type", "hidden");
            field.setAttribute("name", ‘accessToken’);
            field.setAttribute("value", accessToken);
            form.appendChild(field);

            document.body.appendChild(form);
            form.submit();

}

</script>

When you run above code you will find on LoginAuthentication.ashx folder you are getting accessToken there.

 

I hope you enjoyed this tutorial.

Thanks ,

Rajat Jaiswal

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s