[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Auto-submit a form

Posted on 2004-08-30
16
Medium Priority
?
1,097 Views
Last Modified: 2008-03-06
I'm using ASP.Net.  I want to auto-submit a form.  I've tried all the suggestions that I found in other threads.

See below for abbreviated code showing how I write out the form in my Page_Load event.  I have 2 methods in there to auto-submit: an onload and a <script> but neither works.  I have to manually click the Submit button.  

Thanks,
Al

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
        Dim html As New StringBuilder(1000)
        html.Append("<HTML>")
        html.Append("<head>")
   
        html.Append("</head>")
        html.Append("<body onload='javascript: document.Form1.submit();'>")
        html.Append("<form NAME='Form1' action='http://www.somehost.asp' method='post' target='_blank' >")

        html.Append("<INPUT type='hidden' name='SearchType' value='Power'>")

        html.Append("<INPUT type='hidden' name='SearchOption' value='1'>")

        html.Append("<INPUT type='submit' value='Submit' name='~event1'>")

        html.Append("</form>")

        html.Append("<script>")
        html.Append("document.Form1.elements['~event1'].click();")
        html.Append("</script>")

        html.Append("</body>")

        html.Append("</HTML>")

        Response.Clear()
        Response.Write(html.ToString())

    End Sub

0
Comment
Question by:acadalzo
  • 6
  • 6
  • 2
14 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11936576
Any luck with this:

<body onLoad='document.forms[0].submit()'>


Or just near the end of the page:

<script>document.forms[0].submit()</script>

0
 

Author Comment

by:acadalzo
ID: 11937019
changed it but no luck.

html.Append("<body onLoad='document.forms[0].submit()'>")

also:
html.Append("<script>")
html.Append("document.forms[0].submit()")
html.Append("</script>")
html.Append("</body>")
 html.Append("</HTML>")
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11937031
That is very strange. When you view the source, those commands are still there?

ftB
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:fasil_ak
ID: 11939521
Check if u have any pop up blockers..


this is working fine..>>
<HTML>
        <head>
   
        </head>
       
            <body onload='javascript: document.Form1.submit();'>
        <form NAME='Form1' action='http://www.somehost.asp' method='post' target='_blank' >

        <INPUT type='hidden' name='SearchType' value='Power'>

        <INPUT type='hidden' name='SearchOption' value='1'>

        <INPUT type='submit' value='Submit' name='~event1'>

        </form>

       

        </body>

        </HTML>
0
 

Author Comment

by:acadalzo
ID: 11940727

I set the Google pop-up blocker to allow popups on the site, but had not effect, so I uninstalled the Google toolbar.  Still no luck.  However, I did discover that if I choose 'View in Browser' from VS.Net it does the auto submit and takes me directly to the target page, but when I run the page (F5 or Ctrl-F5), it doesn't auto-submit.

When I use 'View in Browser' then either document.forms[0].submit() or document.Form1.submit() will work.

Thanks.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11951903
Won't the page always be viewed in the browser?

FtB
0
 

Author Comment

by:acadalzo
ID: 11952100
FtB,

Yes, but the 'View in Browser' feature I was referring to is within the Visual Studio.Net development environment and is just for previewing the page.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11952258
What happens when you post the page to your site and run it there?

FtB
0
 

Author Comment

by:acadalzo
ID: 11952550
Same thing.  It stops at the page with the Submit button.
0
 

Author Comment

by:acadalzo
ID: 11952642
It has something to do with the target attribute on my form.
If I remove the target='_blank' from the form, then it auto-submits (but I see the submit page briefly).
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11952646
This is strange. I haven't installed and worked with VS.Net yet, so I can't really reproduce what is happening with your code. I do know for certain, however, that this code will submit your form on a regular page.

Is there any possibility that the form is posting and the you just get the page back after the post?

Ftb
0
 

Expert Comment

by:fasil_ak
ID: 11961499
Have u checked it with anyother system.. other than u r now..

Thanks
fasil
0
 

Accepted Solution

by:
acadalzo earned 0 total points
ID: 11961735
I got it working by removing the 'target= _blank' attribute.  
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11962829
Okay. that's great!

Be sure to close this question out:

http://www.experts-exchange.com/Web/Web_Languages/ASP/help.jsp#hs5

FtB
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question