Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 5th, 2009, 04:48 PM
Friend of Wrox
 
Join Date: Mar 2008
Location: So Cal is good enough for you, California, USA.
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>
  #2 (permalink)  
Old February 5th, 2009, 07:09 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
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(); 
}
  #3 (permalink)  
Old February 5th, 2009, 07:22 PM
Friend of Wrox
 
Join Date: Mar 2008
Location: So Cal is good enough for you, California, USA.
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.
  #4 (permalink)  
Old February 5th, 2009, 07:57 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
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)
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Static Scope JaneDean Beginning PHP 0 November 25th, 2008 01: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 12th, 2007 11:51 PM
DataSet Scope jbenson001 ASP.NET 1.x and 2.0 Application Design 2 December 5th, 2003 01:56 PM



All times are GMT -4. The time now is 12:52 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.