Solved

Auto-submit a form

Posted on 2004-08-30
16
1,009 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
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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

16 Experts available now in Live!

Get 1:1 Help Now