Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 748
  • Last Modified:

Auto submit without clicking a button.

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
HunTelWebProgrammer
Asked:
HunTelWebProgrammer
  • 5
  • 3
  • 3
1 Solution
 
ethothsCommented:
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
 
HunTelWebProgrammerAuthor Commented:
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
 
ethothsCommented:
No that does not help. Can you give a step by step account of how you want the page tio work please?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
HunTelWebProgrammerAuthor Commented:
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
 
ethothsCommented:
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
 
HunTelWebProgrammerAuthor Commented:
I replaced the

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

with your code and still doesn't work.
0
 
CollindsouzaCommented:
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
 
HunTelWebProgrammerAuthor Commented:
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
 
CollindsouzaCommented:
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
 
HunTelWebProgrammerAuthor Commented:
I'll give that a try and let you know.
0
 
CollindsouzaCommented:
glad to help....
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now