sajad zarenejad
sajad zarenejad

Reputation: 83

how to Post some parameters and redirect to url in asp webforms

I want to make send a parameter and redirect to another page in another website using asp.net webforms programmatically please help.

I have this in code behind and I dont know how to inject it to page?

string postRefIdScript =
                        @" <script language='javascript' type='text/javascript'>    
                            function postRefId (refIdValue) {
                                var form = document.createElement('form');
                                form.setAttribute('method', 'POST');
                                form.setAttribute('action', '"
                        +PgwSite
                        +@"');         
                                form.setAttribute('target', '_self');
                                var hiddenField = document.createElement('input');              
                                hiddenField.setAttribute('name', 'RefId');
                                hiddenField.setAttribute('value', refIdValue);
                                form.appendChild(hiddenField);
                                document.body.appendChild(form);         
                                form.submit();
                                document.body.removeChild(form);
                            }
                        </script>";

Upvotes: 0

Views: 907

Answers (2)

Tom Troughton
Tom Troughton

Reputation: 4325

It's easy enough to register a JS block from code behind. Just add the following line of code after assigning your postRefIdScript variable.

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "mykey", postRefIdScript);

Upvotes: 1

Apsar
Apsar

Reputation: 105

Add it to to url before redirecting. For example , example.com/siteinfo.aspx?param1=value&param2=value2

Upvotes: 0

Related Questions