HunTelWebProgrammer
asked on
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.Secu rity" %>
<script language="vb" runat="server">
Sub ProcessLogin(objSender As Object, objArgs As EventArgs)
If FormsAuthentication.Authen ticate(txt User.Text, txtPassword.Text) Then
FormsAuthentication.Redire ctFromLogi nPage(txtU ser.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:Tex tBox>
<asp:Button id="Login" onclick="ProcessLogin" runat="server" Text="Login"></asp:Button>
</form>
<script type="text/javascript">
function formSubmit()
{
document.getElementById("g o_in").sub mit()
}
</script>
</head><body>
Here is the code we have...
<%@ Page Language="VB" Debug="true" %>
<%@Import Namespace="System.Web.Secu
<script language="vb" runat="server">
Sub ProcessLogin(objSender As Object, objArgs As EventArgs)
If FormsAuthentication.Authen
FormsAuthentication.Redire
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:Tex
<asp:Button id="Login" onclick="ProcessLogin" runat="server" Text="Login"></asp:Button>
</form>
<script type="text/javascript">
function formSubmit()
{
document.getElementById("g
}
</script>
</head><body>
ASKER
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?
No that does not help. Can you give a step by step account of how you want the page tio work please?
ASKER
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?
Yes that better. My not assign the submit to the client side on load function...
<script for="window" event="onload">
document.getElementById("g o_in").sub mit()
</script>
<script for="window" event="onload">
document.getElementById("g
</script>
ASKER
I replaced the
<script type="text/javascript">
function formSubmit()
{
document.getElementById("g o_in").sub mit()
}
</script>
with your code and still doesn't work.
<script type="text/javascript">
function formSubmit()
{
document.getElementById("g
}
</script>
with your code and still doesn't work.
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('S ubmitButto n').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.
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('S
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.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'll give that a try and let you know.
glad to help....
<form name="go_in" runat="server" defaultbutton="Login">