Solved

Auto submit without clicking a button.

Posted on 2006-11-21
12
729 Views
Last Modified: 2012-05-05
We are working on forms authentication in ASP.NET and we do not want the user to have to click the Submit button.  We are having trouble making it auto-click to allow the user in the code to go in.  It works just fine if they click it, but we want it to auto click.  Any suggestions?
Here is the code we have...
<%@ Page Language="VB" Debug="true" %>
<%@Import Namespace="System.Web.Security" %>
<script language="vb" runat="server">      
      Sub ProcessLogin(objSender As Object, objArgs As EventArgs)

       If FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text) Then
          FormsAuthentication.RedirectFromLoginPage(txtUser.Text, false)
       Else 'if no authentication, send to login page
              response.redirect("http://www.foo.net")
       End If

    End Sub
</script>

<html>
<head>
<title></title>
</head>
<body>
You are at the login page (login.aspx) of the Secure site.<br>
<br>
I'm working on making this page "invisible" - automatically logging into the secure site.<br>
<br>
Just click the Login button (below) to go on into the secure site.<br>
<form name="go_in" runat="server">
<asp:TextBox Visible="false" id="txtUser" runat="server" width="100" Text="jim"></asp:TextBox>
<asp:TextBox Visible="false" id="txtPassword" runat="server" width="100" Text="greetings"></asp:TextBox>
<asp:Button id="Login" onclick="ProcessLogin" runat="server" Text="Login"></asp:Button>
</form>
<script type="text/javascript">
function formSubmit()
{
document.getElementById("go_in").submit()
}
</script>
</head><body>
0
Comment
Question by:HunTelWebProgrammer
  • 5
  • 3
  • 3
12 Comments
 
LVL 11

Expert Comment

by:ethoths
Comment Utility
Not sure what you mean by automatically. How does the form know whwn the user has finished typing? This will work when the user hits return...

<form name="go_in" runat="server" defaultbutton="Login">
0
 
LVL 1

Author Comment

by:HunTelWebProgrammer
Comment Utility
The user is actually in the above code.  We just want to push the credentials to the web.config with the user/password in the code like it is above.  Right now, if you click on the button above it takes you into the secure page with forms authentication.  We just want it to happen automatically.  Does that help?
0
 
LVL 11

Expert Comment

by:ethoths
Comment Utility
No that does not help. Can you give a step by step account of how you want the page tio work please?
0
 
LVL 1

Author Comment

by:HunTelWebProgrammer
Comment Utility
The user is verified even before reaching this page (code above).  I've already filled in the TextBoxes with the required info ("jim" and "greetings").  All I need at this point is to have this form submitted and have the VB script to run for forms authentication ( onclick="ProcessLogin" ).  Any clearer?
0
 
LVL 11

Expert Comment

by:ethoths
Comment Utility
Yes that better. My not assign the submit to the client side on load function...

<script for="window" event="onload">
    document.getElementById("go_in").submit()
</script>
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:HunTelWebProgrammer
Comment Utility
I replaced the

<script type="text/javascript">
function formSubmit()
{
document.getElementById("go_in").submit()
}
</script>

with your code and still doesn't work.
0
 
LVL 5

Expert Comment

by:Collindsouza
Comment Utility
HunTelWebProgrammer
Let me get this right..
what you want is that when a user types in his user name and password.. you want to authenticate him at that point.. without the need of clicking any buttons etc.. meaning submit his username and password automatically.. am i correct..

well you can do this as follows

Can you try to postback the form by raising the submit button.
try this to do a postback in your client side onfocus event handler.

document.getElementById('SubmitButton').click()

where u have a button like one here
<asp:Button id="SubmitButton" runat="server" Text="Submit"></asp:Button>    

Then u can trap the click event of the button on the server side.

0
 
LVL 1

Author Comment

by:HunTelWebProgrammer
Comment Utility
Collindsouza,

In previous pages, an employee enters their email address, is verified against a database maintained by HR, sets up a password, then is redirected to this page (code at top) which uses forms authentication on an ASP.NET 2.0 infrastructure.  Any verified employee will be using the same username and password, which I am filling in the text for them ("jim" and "greetings").  No one wants to have to click another Login button.  So I am trying to eliminate that click, doing so programmatically.  Since each of the TextBoxes is already filled in with text, I don't see the client side onfocus event being an option (if I can get this form to submit without the user actually clicking the Login button, they will never actally see this page).

I've tried every option listing anything similar on this site.  There are many examples for HTML and classic ASP pages, which I've done successfully.  But, for whatever reason, none of these options appears to work on ASP.NET 2.0 using Forms Authentication.  I even verified that the web application is set up in IIS for scripts and executables.  I'm thinking the ProcessLogin script called from Login button isn't firing.
<asp:Button id="Login" onclick="ProcessLogin" runat="server" Text="Login"></asp:Button>

Any specific code examples that work would be greatly appreciated.
0
 
LVL 5

Accepted Solution

by:
Collindsouza earned 500 total points
Comment Utility
I have an example where in i'm invloking a postback when i populate a textbox with some values..

since your trying to achieve something similar.. I hope this helps

here is the complete code for ur solution.

aspx page
<!--
          function abc()
          {
               document.getElementById('aaa').value = "abc";
               document.getElementById('SubmitButton').click();
          }
//-->
          </script>
     </HEAD>
     <body>
          <form id="Form1" method="post" runat="server">
               <asp:TextBox id="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>
               <asp:Button id="SubmitButton" runat="server" Text="Button"></asp:Button>
               <input type="hidden" id="aaa" runat="server">
          </form>
     </body>
</HTML>


Code behind.

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If (Not IsPostBack) Then
            Me.TextBox1.Attributes.Add("onfocus", "javascript:abc();")

        End If
    End Sub

    Private Sub SubmitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
        If aaa.Value = "abc" Then
            Response.Write("Text Box Clicked")
        End If
    End Sub

Cheers
Collin
0
 
LVL 1

Author Comment

by:HunTelWebProgrammer
Comment Utility
I'll give that a try and let you know.
0
 
LVL 5

Expert Comment

by:Collindsouza
Comment Utility
glad to help....
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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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.

728 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

9 Experts available now in Live!

Get 1:1 Help Now