codehutch.com

Online Code Repository

To assign a role to a new user, we usually use the following code. We call this on the CreatedUser event of the ASP.NET CreateUserWizard Control:

protected void CreatedUser(object sender, EventArgs e) {
Roles.AddUserToRole(cuwRegister.UserName, “Registered User”);
}

The code worked fine for me but not when I customized the CreateUserWizard Control where I encountered this error:

The parameter ‘username’ must not be empty.
Parameter name: username

For some reason, the cuwRegister.UserName gives an empty string thus the error. So I used the FindControl method to access the UserName textbox:

TextBox userName = (TextBox)cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl(”UserName”);
Roles.AddUserToRole(userName.Text, “Registered User”);

To learn how to customize the CreateUserWizard Control, go to MSDN.



Tags:

Some tasks are just too complicated for dynamic query building and/or require a greater level of control. To handle this, SubSonic supports stored procedures. Each stored procedure will produce an equivalent static method in the class defined in the configuration file. By default this is SPs. Each method will have one parameter for each stored procedure parameter and return a StoredProcedure object.

SubSonic.StoredProcedure sp = SPs.CustOrderHist(customerID);

If you have created new stored procedures, read my post on how to:
Add New Stored Procedures to dashCommerce

Now that SubSonic recognizes your custom stored procedures, the next question is how to access/get their return value?

Read the rest of this entry »



Tags:

All stored procedures included in the configuration file (Store/App.config) have an equivalent static method in: Store/Models/Generated/StoredProcedures.cs

When I was new to dashCommerce I didn’t figure this out right away.

If you created new stored procedures, you need to update this SubSonic-generated StoredProcedure class to include your new stored procedures. To do so, modify the configuration file, look for the “includeProcedureList” attribute. Add the names of your new stored procedures in the list. Notice this line:

stripSPText=”dashCommerce_Store_”

Read the rest of this entry »



Tags:

I have a web user control (.ascx) that holds my product DataList. This product DataList has an ‘add to cart’ button in each item. When I hit one of the ‘add to cart’ button, the ‘Invalid postback or callback argument’ error shows up. Postback from other controls are fine.

<asp:DataList ID=”dlCatalog” runat=”server” SkinId=”catalogList”>
<ItemTemplate>
<div class=”productBox”>
<div class=”productImageContainer”>
<asp:HyperLink ID=”hlImageLink” runat=”server” NavigateUrl=’<%# GetNavigateUrl(Eval(”ProductId”).ToString(), Eval(”Name”).ToString()) %>’ SkinID=”noDefaultImage” />
</div>
<asp:HyperLink ID=”hlProduct” runat=”server” NavigateUrl=’<%# GetNavigateUrl(Eval(”ProductId”).ToString(), Eval(”Name”).ToString()) %>’ Text=’<%# Eval(”Name”) %>’ CssClass=”catalogProductName” />
<br />
<asp:Label ID=”lblRetailPrice” runat=”server” CssClass=”retailPrice” />
<asp:Label ID=”lblOurPrice” runat=”server” CssClass=”ourPrice” />
<br />
<asp:LinkButton ID=”lbAddToCart” runat=”server” OnCommand=”lbAddToCart_Click” CommandArgument=’<%# Eval(”ProductId”).ToString() + “;” + Eval(”Name”).ToString() %>’ CssClass=”button” Text=”Add To Cart” />
</div>
</ItemTemplate>
</asp:DataList>

The following is the complete error message: Read the rest of this entry »



Tags: