Solved

Auto submit without clicking a button.

Posted on 2006-11-21
12
740 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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