2009-07-25 2 views
1

MasterPage 및 일부 콘텐츠 페이지가있는이 웹 사이트가 있습니다. MasterPage에는 사용자가 MasterPage에있는 'Log In'링크를 클릭 할 때 팝업되는 div가 있습니다. 이 로그인 양식에는 두 개의 텍스트 상자가 있습니다. 하나는 사용자 이름 용이고 다른 하나는 암호 용입니다. 사용자가 양식을 제출하면 인증을 받아야하며 세션에 사용자 정보가 삽입되어야합니다. 처리 할 코드는 모두 MasterPage 코드 뒤에 있습니다.코드에서 액세스 할 때 MasterPage 텍스트 상자가 비어 있습니다.

다음과 같은 문제가 있습니다. MasterPage 클릭 이벤트가 텍스트 상자의 텍스트를 인증 방법에 사용하기 위해 가져올 때 코드는 텍스트를 비어있는 것으로 봅니다.

무엇이 누락 되었습니까? 사업부

bool IsUserAuthenticated = false; 
     string userName = txtUserName.Text; 
     string password = txtPassword.Text; 

     IsUserAuthenticated = masterDataManager.AuthenticateUser(userName, password); 

     if (IsUserAuthenticated) 
     { 
      Session.Add("UserName", userName); 
      lblCurrentUserName.Text = "You are logged in as: " + userName; 

      string script = "<script type=\"text/javascri\">$('#dialogBox').dialog('close');</script>"; 

      if (Page.ClientScript.IsStartupScriptRegistered("closeDialog")) 
      { 
       Page.RegisterStartupScript("closeDialog", script); 
      } 
     } 
     else 
     { 
      lblLoginError.Text = "Username/Password combination does not exist in the database. Please try again."; 
     } 

을 그리고 여기에 있습니다 : : 여기

버튼 클릭 코드와 그는 마스터 페이지에있는 양식 :

ButtonClick

<div id="dialogBox" title="Log In"> 
      <table align="center" style="margin-top: 5px; width: 100%" cellpadding="5" cellspacing="5"> 
       <tr> 
        <td colspan="2"> 
         <asp:Label ID="lblLoginError" runat="server" Text="" CssClass="errorText"></asp:Label> 
        </td> 
       </tr> 
       <tr> 
        <td class="dialogText"> 
         <asp:Label ID="lblUserName" runat="server" Text="User Name: " ForeColor="#c3c003"></asp:Label> 
        </td> 
        <td class="dialogInput"> 
         <asp:TextBox ID="txtUserName" runat="server" BackColor="Black" ForeColor="#c3c003" Width="210px"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td class="dialogText"> 
         <asp:Label ID="lblPassword" runat="server" Text="Password: " ForeColor="#c3c003"></asp:Label> 
        </td> 
        <td class="dialogInput"> 
         <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" BackColor="Black" ForeColor="#c3c003" Width="210px"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td class="dialogInput" colspan="2"> 
      <asp:UpdatePanel runat="server" ID="testupdatepanel"> 
      <ContentTemplate> 
         <asp:ImageButton ID="btnLogin" runat="server" ImageUrl="~/images/loginout.png" ImageAlign="Right" style="padding-top: 15px;" onclick="btnLogin_Click" /> 
         <asp:ImageButton ID="btnCancel" runat="server" ImageUrl="~/images/cancelout.png" ImageAlign="Right" style="padding-top: 15px;" /> 
      </ContentTemplate> 
      </asp:UpdatePanel> 
        </td> 
       </tr> 
      </table> 
     </div> 

txtUserName 및 txtPassword 텍스트 속성은 상자에 텍스트가 있지만 비어 있습니다.

다른 것이 필요한 경우 알려주십시오.

+1

몇 가지 샘플 코드를 게시 할 수 있습니까? – Don

답변

2

게시하려는 글 상자를 포함하도록 업데이트 패널을 이동하십시오.

업데이트 패널을 사용할 때 일반적으로 게시하려는 요소를 다시 정의 할 수 있습니다.

0

텍스트 상자에 runat = "server"속성이 있습니까?

편집 : 로그인 버튼을 updatepanel 외부에두면 작동합니까?

+0

예. 사실, 그것 없이는 컴파일되지 않습니다. –

0

그것은 코드없이 추측하기 어렵다 그러나 여기 어쨌든 몇 가지 있습니다 : 당신이 에게 텍스트 상자의 내용에 액세스를 시도하고있는 페이지 수명주기의 어떤 시점에서

  • 확인합니다.
  • 텍스트 상자를 어떤 방식 으로든 재설정하지 않는지 확인하십시오.
+0

TreeUK의 응답에 추가하려면 페이지로드 이벤트의 텍스트 상자 내용을 다시 설정하고 다시 게시를 확인하지 않고 코드를 보지 않고 말하기가 어려울 수 있습니다. – Steve

관련 문제