Solved

Auto submit without clicking a button.

Posted on 2006-11-21
12
742 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
[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
  • 5
  • 3
  • 3
12 Comments
 
LVL 11

Expert Comment

by:ethoths
ID: 17988689
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
ID: 17988715
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
ID: 17988732
No that does not help. Can you give a step by step account of how you want the page tio work please?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Author Comment

by:HunTelWebProgrammer
ID: 17988778
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
ID: 17988859
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
 
LVL 1

Author Comment

by:HunTelWebProgrammer
ID: 17988971
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
ID: 17995860
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
ID: 17996179
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
ID: 17996565
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
ID: 17996604
I'll give that a try and let you know.
0
 
LVL 5

Expert Comment

by:Collindsouza
ID: 17996696
glad to help....
0

Featured Post

Technology Partners: 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

628 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