Salve ragazzi ho iniziato da poco a lavorare in ASP.NET e stavo provando la registrazione di un nuovo utente.
Ho visto che di base in VWD ci sta una comoda applicazione che ti permette questa operazione. Però volevo anche provare a inserire più informazioni oltre a quelle classiche che ho nel "create user wizrd". Girando in rete alla fine sono riuscito ad arrivare alla soluzione, però mi sono reso conto che con lo script che ho io non funziona il "required field validator". Il "Compare fiedl validator" funziona bene invece.
Questo è il codice:
codice:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="inserimentoRecord_2.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" BackColor="#FFFBD6" BorderColor="#FFDFAD" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" OnCreatedUser="CreateUserWizard1_CreatedUser">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep0" runat="server">
<ContentTemplate>
<table>
<tr>
<th>Billing Information</th>
</tr>
<tr>
<td>Billing Address:</td>
<td>
<asp:TextBox runat="server" ID="BillingAddress" MaxLength="50" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="BillingAddress"
ErrorMessage="Billing address is required"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Billing City:</td>
<td>
<asp:TextBox runat="server" ID="BillingCity" MaxLength="50" Columns="15" />
</td>
</tr>
<tr>
<td>Billing State:</td>
<td>
<asp:TextBox runat="server" ID="BillingState" MaxLength="25" Columns="10" />
</td>
</tr>
<tr>
<td>Billing Zip:</td>
<td>
<asp:TextBox runat="server" ID="BillingZip" MaxLength="10" Columns="10" />
</td>
</tr>
<tr>
<th>Shipping Information</th>
</tr>
<tr>
<td>Shipping Address:</td>
<td>
<asp:TextBox runat="server" ID="ShippingAddress" MaxLength="50" />
</td>
</tr>
<tr>
<td>Shipping City:</td>
<td>
<asp:TextBox runat="server" ID="ShippingCity" MaxLength="50" Columns="15" />
</td>
</tr>
<tr>
<td>Shipping State:</td>
<td>
<asp:TextBox runat="server" ID="ShippingState" MaxLength="25" Columns="10" />
</td>
</tr>
<tr>
<td>Shipping Zip:</td>
<td>
<asp:TextBox runat="server" ID="ShippingZip" MaxLength="10" Columns="10" />
</td>
</tr>
<tr>
<td>
Livello di accesso</td>
<td>
<asp:DropDownList ID="livelloAccesso" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Amministratore</asp:ListItem>
<asp:ListItem>Utente</asp:ListItem>
<asp:ListItem>Cliente</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<th>User Information</th>
</tr>
<tr>
<td>Username:</td>
<td>
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator9" ControlToValidate="UserName"
ErrorMessage="Username is required." />
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator10" ControlToValidate="Password"
ErrorMessage="Password is required." />
</td>
</tr>
<tr>
<td>Confirm Password:</td>
<td>
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator13" ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required." />
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<asp:TextBox runat="server" ID="Email" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator11" ControlToValidate="Email"
ErrorMessage="Email is required." />
</td>
</tr>
<tr>
<td>Question:</td>
<td>
<asp:TextBox runat="server" ID="Question" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator12" ControlToValidate="Question"
ErrorMessage="Question is required." />
</td>
</tr>
<tr>
<td>Answer:</td>
<td>
<asp:TextBox runat="server" ID="Answer" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator14" ControlToValidate="Answer"
ErrorMessage="Answer is required." />
</td>
</tr>
<tr>
<td colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."></asp:CompareValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
<asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"
InsertCommand="INSERT INTO [UserAddresses] ([UserId], [BillingAddress], [BillingCity], [BillingState], [BillingZip], [ShippingAddress], [ShippingCity], [ShippingState], [ShippingZip], [livelloAccesso]) VALUES (@UserId, @BillingAddress, @BillingCity, @BillingState, @BillingZip, @ShippingAddress, @ShippingCity, @ShippingState, @ShippingZip, @livelloAccesso)"
ProviderName="<%$ ConnectionStrings:ASPNETDBConnectionString1.ProviderName %>">
<InsertParameters>
<asp:ControlParameter Name="BillingAddress" Type="String" ControlID="BillingAddress" PropertyName="Text" />
<asp:ControlParameter Name="BillingCity" Type="String" ControlID="BillingCity" PropertyName="Text" />
<asp:ControlParameter Name="BillingState" Type="String" ControlID="BillingState" PropertyName="Text" />
<asp:ControlParameter Name="BillingZip" Type="String" ControlID="BillingZip" PropertyName="Text" />
<asp:ControlParameter Name="ShippingAddress" Type="String" ControlID="ShippingAddress" PropertyName="Text" />
<asp:ControlParameter Name="ShippingCity" Type="String" ControlID="ShippingCity" PropertyName="Text" />
<asp:ControlParameter Name="ShippingState" Type="String" ControlID="ShippingState" PropertyName="Text" />
<asp:ControlParameter Name="ShippingZip" Type="String" ControlID="ShippingZip" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
<NavigationButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#990000" />
<HeaderStyle BackColor="#FFCC66" BorderColor="#FFFBD6" BorderStyle="Solid" BorderWidth="2px"
Font-Bold="True" Font-Size="0.9em" ForeColor="#333333" HorizontalAlign="Center" />
<CreateUserButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#990000" />
<ContinueButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" ForeColor="#990000" />
<SideBarStyle BackColor="#990000" Font-Size="0.9em" VerticalAlign="Top" />
<TitleTextStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<SideBarButtonStyle ForeColor="White" />
</asp:CreateUserWizard>
</div>
</form>
</body>
</html>
Questo è il codice del file allegato:
codice:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
TextBox UserNameTextBox =
(TextBox)CreateUserWizardStep0.ContentTemplateContainer.FindControl("UserName");
SqlDataSource DataSource =
(SqlDataSource)CreateUserWizardStep0.ContentTemplateContainer.FindControl("InsertExtraInfo");
MembershipUser User = Membership.GetUser(UserNameTextBox.Text);
object UserGUID = User.ProviderUserKey;
DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
DataSource.Insert();
}
}
Per ora il required fiel validator è solo su alcuni campi per fare delle prove.
Da cosa può dipendere??
Grazie a tutti in anticipo.