Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1060411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:19:22+00:00 2026-05-16T18:19:22+00:00

Dynamicaly adding a form to a page and submitting it in c#. Works fine

  • 0

Dynamicaly adding a form to a page and submitting it in c#. Works fine in IE but just realized its not working in chrome. Im doing it as a function of a PayPal Transaction Object I built for a little ecomerce app. Here is the code.

    private void PayPalPostScriptLONG(Page page)
    {
        StringBuilder strScript = new StringBuilder();
        strScript.Append("<script language='javascript'>");
        if (UserID == string.Empty || EventID == string.Empty || TransactionType == string.Empty)
        {
            strScript.Append("alert('missing event, user, or transactiontype');");
        }
        else
        {
            strScript.AppendFormat("myform=document.createElement('form'); myform.method='post'; myform.target='_top'; myform.action='{0}'; myform.name='frmPP';", Paypal);
            strScript.AppendFormat("input1=document.createElement('input'); input1.type='hidden'; input1.name='cmd'; input1.value='{0}'; myform.appendChild(input1);", Cmd);
            strScript.AppendFormat("input2=document.createElement('input'); input2.type='hidden'; input2.name='business'; input2.value='{0}'; myform.appendChild(input2);", Business);
            strScript.AppendFormat("input3=document.createElement('input'); input3.type='hidden'; input3.name='item_name'; input3.value='{0}'; myform.appendChild(input3);", Item_name);
            strScript.AppendFormat("input4=document.createElement('input'); input4.type='hidden'; input4.name='amount'; input4.value='{0}'; myform.appendChild(input4);", Amount);
            strScript.AppendFormat("input5=document.createElement('input'); input5.type='hidden'; input5.name='return'; input5.value='{0}'; myform.appendChild(input5);", ReturnURL);
            strScript.AppendFormat("input6=document.createElement('input'); input6.type='hidden'; input6.name='custom'; input6.value='{0}'; myform.appendChild(input6);", Custom);
            strScript.AppendFormat("input7=document.createElement('input'); input7.type='hidden'; input7.name='on0'; input7.value='uID'; myform.appendChild(input7);");
            strScript.AppendFormat("input8=document.createElement('input'); input8.type='hidden'; input8.name='os0'; input8.value='{0}'; myform.appendChild(input8);", UserID);
            strScript.AppendFormat("input9=document.createElement('input'); input9.type='hidden'; input9.name='on1'; input9.value='eID'; myform.appendChild(input9);");
            strScript.AppendFormat("input10=document.createElement('input'); input10.type='hidden'; input10.name='os1'; input10.value='{0}'; myform.appendChild(input10);", EventID);
            strScript.AppendFormat("input11=document.createElement('input'); input11.type='hidden'; input11.name='on2'; input11.value='type'; myform.appendChild(input11);");
            strScript.AppendFormat("input12=document.createElement('input'); input12.type='hidden'; input12.name='os2'; input12.value='{0}'; myform.appendChild(input12);", TransactionType);
            strScript.AppendFormat("input13=document.createElement('input'); input13.type='hidden'; input13.name='address1'; input13.value='{0}'; myform.appendChild(input13);", Address1);
            strScript.AppendFormat("input14=document.createElement('input'); input14.type='hidden'; input14.name='address2'; input14.value='{0}'; myform.appendChild(input14);", Address2);
            strScript.AppendFormat("input15=document.createElement('input'); input15.type='hidden'; input15.name='city'; input15.value='{0}'; myform.appendChild(input15);", City);
            strScript.AppendFormat("input16=document.createElement('input'); input16.type='hidden'; input16.name='email'; input16.value='{0}'; myform.appendChild(input16);", Email);
            strScript.AppendFormat("input17=document.createElement('input'); input17.type='hidden'; input17.name='first_name'; input17.value='{0}'; myform.appendChild(input17);", First_name);
            strScript.AppendFormat("input18=document.createElement('input'); input18.type='hidden'; input18.name='last_name'; input18.value='{0}'; myform.appendChild(input18);", Last_name);
            strScript.AppendFormat("input19=document.createElement('input'); input19.type='hidden'; input19.name='state'; input19.value='{0}'; myform.appendChild(input19);", State);
            strScript.AppendFormat("input20=document.createElement('input'); input20.type='hidden'; input20.name='zip'; input20.value='{0}'; myform.appendChild(input20);", Zip);
            strScript.AppendFormat("input21=document.createElement('input'); input21.type='hidden'; input21.name='night_ phone_a'; input21.value='{0}'; myform.appendChild(input21);", PhonePart1);
            strScript.AppendFormat("input22=document.createElement('input'); input22.type='hidden'; input22.name='night_ phone_b'; input22.value='{0}'; myform.appendChild(input22);", PhonePart2);
            strScript.AppendFormat("input23=document.createElement('input'); input23.type='hidden'; input23.name='night_ phone_c'; input23.value='{0}'; myform.appendChild(input23);", PhonePart3);


            strScript.Append("document.appendChild(myform);");
            strScript.Append("myform.submit();");
        }
        strScript.Append("</script>");
        page.ClientScript.RegisterClientScriptBlock(typeof(Page), "PPSubmit", strScript.ToString());
    }

Any help would be greatly appreciated!!

Thanks!


i ended up taking jumpdarts advice and using the following code:

    private string GetForm()
    {            
        StringBuilder ppForm = new StringBuilder();
        ppForm.AppendFormat("<Form name=\"frmPP\" id=\"frmPP\" action=\"{0}\" method=\"post\" target=\"_top\" \">", Paypal);
        AddInput(ppForm,"cmd",Cmd);
        AddInput(ppForm,"business",Business);
        AddInput(ppForm,"item_name",Item_name);
        AddInput(ppForm,"amount",Amount);
        AddInput(ppForm,"return",ReturnURL);
        AddInput(ppForm,"custom",Custom);
        AddInput(ppForm,"on0",UserID);
        AddInput(ppForm,"os0","uID");
        AddInput(ppForm,"on1",EventID);
        AddInput(ppForm,"os1","eID");
        AddInput(ppForm,"on2",TransactionType);
        AddInput(ppForm,"os2","type");
        AddInput(ppForm,"address1",Address1);
        AddInput(ppForm,"address2",Address2);
        AddInput(ppForm,"city",City);
        AddInput(ppForm,"email",Email);
        AddInput(ppForm,"first_name",First_name);
        AddInput(ppForm,"last_name",Last_name);
        AddInput(ppForm,"state",State);
        AddInput(ppForm,"zip",Zip);
        AddInput(ppForm,"night_ phone_a",PhonePart1);
        AddInput(ppForm,"night_ phone_b",PhonePart2);
        AddInput(ppForm,"night_ phone_c",PhonePart3);

        return ppForm.ToString();
    }

    private void AddInput(StringBuilder ppForm, string name, string value)
    {
        ppForm.AppendFormat("<input type=\"hidden\" name=\"{0}\" value=\"{1}\">", name, value);
    }

    private void PayPalPostScriptLONG(Page page)
    {

        HttpContext.Current.Response.Write(GetForm());//add form to page

        StringBuilder strScript = new StringBuilder();
        strScript.Append("<script language='javascript'>");
        if (UserID == string.Empty || EventID == string.Empty || TransactionType == string.Empty)
        {
            strScript.Append("alert('missing event, user, or transactiontype');");
        }
        strScript.Append("var ctlForm = document.getElementById('frmPP');");
        strScript.Append("ctlForm.submit();");
        strScript.Append("</script>");
        page.ClientScript.RegisterClientScriptBlock(typeof(Page), "PPSubmit", strScript.ToString());

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:19:23+00:00Added an answer on May 16, 2026 at 6:19 pm

    Dont do it this way. Write your form out as html text to your response then append a jscript function that finds it and submits it.

    Like so:

    Response.Write(<Form...);
    StringBuilder strScript = new StringBuilder();
    strScript.Append("<script language='javascript'>");
    strScript.Append("var daForm = document.getElementById('frmPP');");
    strScript.Append("daForm.submit();");
    strScript.Append("</script>");
    ClientScript.RegisterClientScriptBlock(typeof(Page), "PPSubmit", strScript.ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im adding textboxes (not a fixed number of textboxes) dynamically to a form on
I have a form on my page and am dynamically adding controls to the
My page creates rows dynamically using jQuery but when I refresh the form, the
I'm dynamically adding a custom user control to the page as per this post
I am currently dynamically adding content to the page with the help of Jquery.
I'm having trouble dynamically adding controls inside an update panel with partial postbacks. I've
I have a flowpanel that I'm dynamically adding usercontrols to. I want it to
I am creating a Rails plugin and it is dynamically adding a method to
I am adding some user controls dynamically to a PlaceHolder server control. My user
I'm dynamically loading user controls adding them to the Controls collection of the web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.