[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Auto-submit a form

Posted on 2004-08-30
16
Medium Priority
?
1,084 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
16 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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