?
Solved

Auto-submit a form

Posted on 2004-08-30
16
Medium Priority
?
1,068 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
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

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!

Question has a verified solution.

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

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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

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