• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

How to build a login web control function with a page that has many textbox?

Hi

I build a aspx webpage which has 10 textbox and each textbox has submit button and javascript validation. say product.aspx

Now, I need to add a login textbox on the top. After login, it will show: you are logged in as XXX and show logout button.

Can I do it in the same product.aspx page after login?

Can I use web control ascx page and other technology to do that?

Thanks

0
techques
Asked:
techques
  • 7
  • 7
1 Solution
 
Rupesh PCommented:
Create a user control with login related controls and labels. And incorporate it in to the products.aspx file.

In the login user control in addition to the username , password textboxes add a label to show the status like "Logged in as...."

Suppose you have a login button ,
In the click event of the login button
     if the caption of the button is "Login"
    {
        check username and password
        if validated successfully
         {
            change the caption of the login button to "Logout"
            and update the status label with "Logged in as...."
         }
    }
     if the caption of the button is "Logout"
    {
        change the status label as "Not logged in"
         and change button caption to "Login"
   }




 



0
 
JuanCarnigliaCommented:
Generally, it is not a good idea to have the login form on a page that has other form controls.

As you have setup your web page, if a user happens to fill out the form, and then remembers to login, after page refresh (Postback) he will loose all form data!.. And will have to fill it up again.

One solution (if you still want to have everything on the same page) is to use AJAX. This would allow you to postback only the "Login part", and keep all the data on the page.

If you decide to go with this idea, check www.asp.net/AJAX.

Good Luck
0
 
techquesAuthor Commented:
Hi

I use asp:panel with login and logout to fix it with session.

However, the javascript validation does not work. Here is the code:

Since all textbox have individual js validation, I tried onsubmit() and bLogin.Attributes.Add("onclick", "return CheckInput();"); both did not work.

Any idea?



<script type="text/javascript">
function CheckInput()
{
	var ft2 = document.all;		
	if(isNaN(ft2.productid.value))
	{
		window.alert('Please input ID');
		ft2.productid.focus();
		return false;
	}		
}</script>
 
<asp:button id="bLogin" runat="server" text="Login" ValidationGroup="ControlWebTop" OnClick="return CheckInput();"></asp:button>

Open in new window

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.

 
JuanCarnigliaCommented:
Shouldn't you return true if the value is a number? I mean, aren't you missing a "return true" clause ?

Greetings
0
 
techquesAuthor Commented:
no, it does not work even add return true clause

and i changed to use onclientclick still not work
0
 
JuanCarnigliaCommented:
The explorer is not displaying any errors? Are you checking the Javascript console?
0
 
techquesAuthor Commented:
I saw there is error, but it refreshes very fast and I cannot view it when it has error.
How should I debug javascript?
0
 
JuanCarnigliaCommented:
The easy way.

Add:

function CheckInput()
{
  alert("CheckPoint 1");

        var ft2 = document.all;        
  alert("CheckPoint 2");

        if(isNaN(ft2.productid.value))
        {
  alert("CheckPoint 3");

                window.alert('Please input ID');

                ft2.productid.focus();
alert("CheckPoint 4");
                return false;
        }              
alert("CheckPoint 5");
}</script>


This will tell you where it stops working.
0
 
techquesAuthor Commented:
It executes alert("CheckPoint 2");
and then stop

So, any idea?
0
 
JuanCarnigliaCommented:
Maybe it is not finding productid. Is it within the Form?

Try using document.all("documentid").value instead, see if it works.
0
 
techquesAuthor Commented:
If I changed it to var ft2 = document.all("documentid").value;

It exeucte checkpoint 1 only

Yes, it is within the form
<form id="index" runat="server">
<ASP:PlaceHolder id="top" runat="server"/>
</form>
0
 
JuanCarnigliaCommented:
I don't see it on the form !... Can you post all the code? Or maybe as an attachment.
0
 
techquesAuthor Commented:
Here is the full source code:
<%@ Register src="top.ascx" TagName="top" TagPrefix="top" %>
<form id="index" runat="server">
<ASP:PlaceHolder id="top" runat="server"/>
</form>
 
//top.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="top.ascx.cs" Inherits="Project.top" %>
<script type="text/javascript">
function CheckInput()
{
        alert("CheckPoint 1");
	var ft2 = document.all;
	alert("CheckPoint 2");		
	if(isNaN(ft2.productid.value))
	{
	        alert("CheckPoint 3");
		window.alert('Please input productid');
		ft2.productid.focus();
		alert("CheckPoint 4");
		return false;
	}		
	alert("CheckPoint 5");
}
</script>
<table border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td>		
		<asp:panel id="login" Runat="server"> 
		<asp:textbox id="productid" runat="server"></asp:textbox>
        <asp:requiredfieldvalidator id="Requiredproductid" runat="server" EnableViewState="False" ControlToValidate="productid" Display="None" ErrorMessage="Please input" ValidationGroup="Control1"></asp:requiredfieldvalidator>
	    <asp:validationsummary id="ValidationSummary" runat="server" EnableViewState="False" ShowMessageBox="True" ShowSummary="False" ValidationGroup="Control1"></asp:validationsummary>
	    <asp:button id="bLogin" runat="server" text="login" ValidationGroup="Control1"></asp:button>
		</asp:panel>
		
		<asp:panel id="logout" Runat="server">
        <asp:button id="bLogout" runat="server" text="logout"></asp:button>
        </asp:panel>
		</td>
	</tr>
</table>

Open in new window

0
 
JuanCarnigliaCommented:
Maybe you should try to check everything on the server side, and not using JavaScript.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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