With .NET 2.0 its all easy :)
Drag and drop a CreateUserWizard in your page and set the OnCreatedUser=CreateUserWizard1_CreatedUser
Add a Wizard Step as below
asp:WizardStep ID="AddRolesStep" Runat="server" AllowReturn="False" Title="Step 2: Assign User To Roles"
OnActivate="AssignUserToRoles_Activate" OnDeactivate="AssignUserToRoles_Deactivate"
with a Listbox or any control to display the roles
After that in code behind add
public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
// Create an empty Profile for the newly created user
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);
// Save the profile - must be done since we explicitly created this profile instance
p.Save();
}
// Activate event fires when the user hits "next" in the CreateUserWizard
public void AssignUserToRoles_Activate(object sender, EventArgs e)
{
// Databind list of roles in the role manager system to a listbox in the wizard
AvailableRoles.DataSource = Roles.GetAllRoles(); ;
AvailableRoles.DataBind();
}
// Deactivate event fires when user hits "next" in the CreateUserWizard
public void AssignUserToRoles_Deactivate(object sender, EventArgs e)
{
// Add user to all selected roles from the roles listbox
for (int i = 0; i < AvailableRoles.Items.Count; i++)
{
if (AvailableRoles.Items[i].Selected == true)
Roles.AddUserToRole(CreateUserWizard1.UserName, AvailableRoles.Items[i].Value);
}
}
Also dont forget to add in web.config file
< profile enabled="true" >
<properties>
<add name="Email" />
</properties>
</profile>
else you will wonder which namespace to add for ProfileCommon, compilation error will show, you are missing reference.
That's it, a Create User with associating to roles are ready!!!
Thursday, October 4, 2007
Wednesday, September 19, 2007
Associating events to dynamically created controls
Continued......
After the controls that are created dynamically now the questions is events of that controls
i came across this microsoft link which looks helpfull and is trying to match with my requirement.
After the controls that are created dynamically now the questions is events of that controls
i came across this microsoft link which looks helpfull and is trying to match with my requirement.
Add rows to asp table web control dynamically
Came across this 'constraint' recently and was amazed to find not much solution exist in .net world for this.
Requirement: Add rows dynamically to an asp table, web control(or say dynamically you want to keep on adding controls on click / some event)
Issue: I was able to add row but previously added row 'vanishes' from UI
Reason: Viewstate of dynamically created control is lost on next post back
Solution:
Added a session to store state of table and to render/recreate the control on post back
code as below in page_load event
if (Session["rowList"] == null)
{
//No row list, Create it.
rowList = new List();
}
else
{
rowList = (List)Session["rowList"];
}
//Recreate the table. (Prevents loosing data already entered into textboxes.)
DisplayTable();
There is an addrow method called on click (/ any event you like )
You have to add our newly formed row to our row List as below.
rowList.Add(tableRow);
Then save our Row List on to the session
Session.Add("rowList", rowList);
Call the DisplayTable();
Finally recreating table as below in DisplayTable function
protected void DisplayTable()
{
//Run through the row list, and add each one to the Table's Row Collection.
foreach (TableRow tr in rowList)
Table1.Rows.Add(tr);
}
Any other suggestion / idea you have please post it here....coz i am still not convinced by this idea :(
Requirement: Add rows dynamically to an asp table, web control(or say dynamically you want to keep on adding controls on click / some event)
Issue: I was able to add row but previously added row 'vanishes' from UI
Reason: Viewstate of dynamically created control is lost on next post back
Solution:
Added a session to store state of table and to render/recreate the control on post back
code as below in page_load event
if (Session["rowList"] == null)
{
//No row list, Create it.
rowList = new List
}
else
{
rowList = (List
}
//Recreate the table. (Prevents loosing data already entered into textboxes.)
DisplayTable();
There is an addrow method called on click (/ any event you like )
You have to add our newly formed row to our row List as below.
rowList.Add(tableRow);
Then save our Row List on to the session
Session.Add("rowList", rowList);
Call the DisplayTable();
Finally recreating table as below in DisplayTable function
protected void DisplayTable()
{
//Run through the row list, and add each one to the Table's Row Collection.
foreach (TableRow tr in rowList)
Table1.Rows.Add(tr);
}
Any other suggestion / idea you have please post it here....coz i am still not convinced by this idea :(
Thursday, September 13, 2007
New features of .NET 2.0 framework
Came across this link.........lists features of .NET framework 2.0
http://asptoday.com/Content.aspx?id=2368
http://asptoday.com/Content.aspx?id=2368
Subscribe to:
Posts (Atom)