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

techquesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.