OnLoggedIn not workinghttp://forums.asp.net/t/1791845.aspx/1?OnLoggedIn+not+workingSat, 14 Apr 2012 07:35:09 -040017918454928065http://forums.asp.net/p/1791845/4928065.aspx/1?OnLoggedIn+not+workingOnLoggedIn not working <p>Page directive in the .aspx page:</p> <p>&lt;%@ Page Title=&quot;&quot; Language=&quot;C#&quot; MasterPageFile=&quot;~/Master/ContractsAndMore.Master&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;Login.aspx.cs&quot; Inherits=&quot;ContractsAndMore.Account.LoginPage&quot; %&gt;</p> <p>I've defined the Login object as shown below:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Login ID=&quot;Login1&quot; runat=&quot;server&quot; DestinationPageUrl=&quot;~/LoggedIn/Default.aspx&quot; OnLoggedIn=&quot;OnLoggedIn&quot; &gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;LayoutTemplate&gt;</p> <p>In the code behind page&nbsp;I have the following:</p> <p>namespace ContractsAndMore.Account<br> {<br> &nbsp;&nbsp;&nbsp; public partial class LoginPage : System.Web.UI.Page<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected void Page_Load(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void OnLoggedIn(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Get EMPL_PK from T_EMPL and store in Session variable<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var connectionString = ConfigurationManager.ConnectionStrings[&quot;LocalSqlServer&quot;].ConnectionString;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ContractSystemDataContext db = new ContractSystemDataContext(connectionString);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MembershipUser currentUser = Membership.GetUser();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Guid guidUserID = new Guid(currentUser.ProviderUserKey.ToString());<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T_EMPLGetEmplCobyGUIDResult emplValues = db.T_EMPLGetEmplCobyGUID(guidUserID).FirstOrDefault();</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Int32 emplPK = emplValues.Empl_pk.Value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Int32 emplCmpyFK = emplValues.EMPL_CMPY_FK.Value;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String emplCmpyName = emplValues.Cmpy_NAME;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String emplFirstName = emplValues.EMPL_FIRST_NAME;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String emplLastName = emplValues.EMPL_LAST_NAME;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session.Add(&quot;emplPK&quot;, emplPK);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session.Add(&quot;emplCmpyFK&quot;, emplCmpyFK);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session.Add(&quot;emplCmpyName&quot;, emplCmpyName);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session.Add(&quot;emplFirstName&quot;, emplFirstName);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session.Add(&quot;emplLastName&quot;, emplLastName);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>}</p> <p>Can anyone tell me why it's not compiling?</p> <p>Thanks&nbsp;</p> <p>&nbsp;</p> <p><b>Compiler Error Message: </b>CS1061: 'ASP.account_login_aspx' does not contain a definition for 'OnLoggedIn' and no extension method 'OnLoggedIn' accepting a first argument of type 'ASP.account_login_aspx' could be found (are you missing a using directive or an assembly reference?)<br> <br> </p> 2012-04-12T03:15:52-04:004928545http://forums.asp.net/p/1791845/4928545.aspx/1?Re+OnLoggedIn+not+workingRe: OnLoggedIn not working <p>Try</p> <p><strong>protected</strong> void OnLoggedIn(object sender, EventArgs e)</p> <p>also:</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>MParkhouse</h4> MembershipUser currentUser = Membership.GetUser();<br> </blockquote> <p></p> <p>This won't work, because in the OnLoggedIn event, there's no current user, the current user is only available AFTER the next request. So instead of Membership.GetUser(), you need to use Membership.GetUser(<strong>Login1.Username</strong>);</p> 2012-04-12T08:13:56-04:004930054http://forums.asp.net/p/1791845/4930054.aspx/1?Re+OnLoggedIn+not+workingRe: OnLoggedIn not working <p>Adding the protected made the code compile.&nbsp;&nbsp; Thanks for that info. &nbsp;</p> <p>However, I can not use Membership.GetUser(<strong>Login1.Username</strong>); because the UserName textbox is in a LayoutTemplate.&nbsp; However, I was able to use your suggestion and do the following:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String userName = ((TextBox)Login1.FindControl(&quot;UserName&quot;)).Text;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MembershipUser currentUser = Membership.GetUser(userName);</p> <p>Thanks very much!</p> 2012-04-12T21:47:01-04:004930482http://forums.asp.net/p/1791845/4930482.aspx/1?Re+OnLoggedIn+not+workingRe: OnLoggedIn not working <p></p> <blockquote><span class="icon-blockquote"></span> <h4>MParkhouse</h4> However, I can not use Membership.GetUser(<strong>Login1.Username</strong>); because the UserName textbox is in a LayoutTemplate.</blockquote> <p></p> <p>Did you test this or do you assume you can't? When you've a TextBox called &quot;UserName&quot; in your LayoutTemplate, which you have and should have, you can use Login1.UserName. How do you think the Control knows which TextBox to use for the UserName (and PassWord)?</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.username.aspx">http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.username.aspx</a></p> 2012-04-13T06:52:53-04:004931920http://forums.asp.net/p/1791845/4931920.aspx/1?Re+OnLoggedIn+not+workingRe: OnLoggedIn not working <p>Yes, I tested it.&nbsp; When I tried&nbsp;refering to&nbsp;the name of the textbox, it was not recognized as being&nbsp;a control on&nbsp;the page.&nbsp; I had seen a previous post on the web that mentioned the fact that controls in a LayoutTemplate couldnot be referenced directly.</p> 2012-04-14T01:13:37-04:004932128http://forums.asp.net/p/1791845/4932128.aspx/1?Re+OnLoggedIn+not+workingRe: OnLoggedIn not working <p></p> <blockquote><span class="icon-blockquote"></span> <h4>MParkhouse</h4> Yes, I tested it.</blockquote> <p></p> <p>Really?</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>MParkhouse</h4> When I tried&nbsp;refering to&nbsp;the name of the textbox, it was not recognized as being&nbsp;a control on&nbsp;the page.</blockquote> <p></p> <p>Username is a Property of the Login control (see the link in my previous reply), and it is accesible if you're using a (layout) template or not. In When using a Layouttemplate, you need to use 2 textboxes&nbsp;named UserName and Password,&nbsp;which are used internally by the login control to expose the UserName and Password Property. So it is&nbsp;NOT necessary to use findcontrol tp get the Username.</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>MParkhouse</h4> had seen a previous post on the web that mentioned the fact that controls in a LayoutTemplate couldnot be referenced directly.</blockquote> <p></p> <p>Ussually, this is true. But Login1.UserName isn't refering to a TextBox directly, it is the UserName Property of the Login Control, which is available during all phases of the Page LifeCycle. The Login control itself is using ViewState to pass the value from the TextBox to the Property....</p> <p>&nbsp;</p> 2012-04-14T07:35:09-04:00