Wrox Programmer Forums
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 5th, 2009, 05:48 PM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default scope issue with LoginView

i got this code here, and in the btn_DeliteUser method i need to access tbUserName which resides in a loginview control. the error i get is that tbUserName doesnt exist in the current context.
<code>
<scriptrunat="server">
protectedvoid Page_Load(object sender, EventArgs e)
{

}
protectedvoid btn_DeliteUser(object sender, EventArgs e)
{
string userName = tbUserName.Text;

Membership.DeleteUser(userName, true);
}
</script>
</code>

here is my code that makes the loginview
<code>
<asp:LoginView
ID="LoginView1"runat="server">
<LoggedInTemplate>
<asp:GridView
id="grdUsers"
runat="server"
DataSourceID="srcUsers"/>
<asp:ObjectDataSource
id="srcUsers"
runat="server"
TypeName="System.Web.Security.Membership"
SelectMethod="GetAllUsers"/>
<hr/>
</LoggedInTemplate>
<RoleGroups>
<asp:RoleGroupRoles="Administrator">
<ContentTemplate>
<asp:LabelID="Label1"runat="server"Text="User Name:"/>
<asp:TextBox
id="tbUserName"
runat="server"
TextMode="SingleLine"style="margin-left: 10px"/>
<asp:Button
id="btnDeliteUser"
runat="server"
OnClick="btn_DeliteUser"
Text="Delite User"style="margin-left: 15px"/>
<asp:GridView
id="grdUsers"
runat="server"
DataSourceID="srcUsers"Width="925px"/>
<asp:ObjectDataSource
id="srcUsers"
runat="server"
TypeName="System.Web.Security.Membership"
SelectMethod="GetAllUsers"/>
<hr/>
</ContentTemplate>
</asp:RoleGroup>
<asp:RoleGroupRoles="Moderator">
<ContentTemplate>
<hr/>
<asp:GridView
id="grdUsers"
runat="server"
DataSourceID="srcUsers"/>
<asp:ObjectDataSource
id="srcUsers"
runat="server"
TypeName="System.Web.Security.Membership"
SelectMethod="GetAllUsers"/>
<hr/>
</ContentTemplate>
</asp:RoleGroup>
<asp:RoleGroupRoles="User">
<ContentTemplate>
<hr/>
<asp:GridView
id="grdUsers"
runat="server"
DataSourceID="srcUsers"/>
<asp:ObjectDataSource
id="srcUsers"
runat="server"
TypeName="System.Web.Security.Membership"
SelectMethod="GetAllUsers"/>
<hr/>
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
</code>
 
Old February 5th, 2009, 08:09 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Code:
protected void btnDeleteUser_Click(object sender, EventArgs e)
{
 string userName = ((TextBox) LoginView1.FindControl("tbUserName")).Text;

 if (userName != null) 
    Membership.DeleteUser(userName, true);
}
May I offer a couple of other suggestions?

1. The DeleteUser method will throw an ArgumentException if userName is an empty string. You need to have a RequiredFieldValidator on tbUserName to eliminate the possibility of that happening.

2. Why do you have so many ObjectDataSources that all represent the exact same object? Just have ONE and put it outside of the LoginView so that all the GridViews can use the same one.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old February 5th, 2009, 08:22 PM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

o wow... lol i cant believe i didnt see that.

i am going through my asp book and taking code out i need. basically looking stuff up and programming according to my needs. but yeah. i should change that... no reason for ... i believe 3 datasources like that. thanks for the reply.
 
Old February 5th, 2009, 08:57 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Just remember to click the Thanks button (I'm collecting them ;-)
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
iceman90289 (February 5th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Static Scope JaneDean Beginning PHP 0 November 25th, 2008 02:07 AM
Scope Issue iceman90289 C# 2005 8 April 5th, 2008 03:41 PM
Trying to use a LoginView within a Repeater BSpeerTX ASP.NET 2.0 Basics 2 April 23rd, 2007 10:57 AM
what is the scope of PHP raaj Beginning PHP 1 February 13th, 2007 12:51 AM
DataSet Scope jbenson001 ASP.NET 1.x and 2.0 Application Design 2 December 5th, 2003 02:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.