Solved

Auto-submit a form

Posted on 2004-08-30
16
992 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
16 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
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
Comment Utility
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
Comment Utility
That is very strange. When you view the source, those commands are still there?

ftB
0
 

Expert Comment

by:fasil_ak
Comment Utility
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
Comment Utility

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
Comment Utility
Won't the page always be viewed in the browser?

FtB
0
 

Author Comment

by:acadalzo
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 46

Expert Comment

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

FtB
0
 

Author Comment

by:acadalzo
Comment Utility
Same thing.  It stops at the page with the Submit button.
0
 

Author Comment

by:acadalzo
Comment Utility
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
Comment Utility
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
Comment Utility
Have u checked it with anyother system.. other than u r now..

Thanks
fasil
0
 

Accepted Solution

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

Expert Comment

by:fritz_the_blank
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ASP equivalent to Windows findstr 3 58
Classic ASP - cannot get to correct path 17 62
CSS Question.. 3 72
API not working 33 47
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now