這里以createuserwizard 為例說明注冊用戶向導的常規使用
1)使用默認的向導控件功能
默認的注冊向導的使用向導的簡單,簡單到如下只要一句話代碼的地步:
<asp:createuserwizard id="createuserwizardcontrol" runat="server"/>
無需要額外的代碼就能夠完成用戶的注冊,將注冊的信息寫入aspnetdb.mdf數據庫。
2)使用默認id
一些不安分的用戶開始不滿足上面的功能:雖然簡單,但是太死板,沒有靈活性,例如在用戶名,我想要驗證用戶名必須是字母或者是數字,此時利用上面的代碼就不能夠完成,因此不得不使用模板,或許類似的代碼類似如下:
<asp:createuserwizard id="createuserwizardcontrol" runat="server">
<wizardsteps>
<asp:createuserwizardstep id="createuserwizardstep1" runat="server" title="account details:">
<contenttemplate>
user name:
<asp:textbox runat="server" id="username" ></asp:textbox></span>
<asp:requiredfieldvalidator runat="server" controltovalidate="username" validationgroup="createuserwizardcontrol"
errormessage="user name is required." tooltip="user name is required." id="usernamerequired"
display="dynamic">
</asp:requiredfieldvalidator>
password: <asp:textbox runat="server" textmode="password" id="password" cssclass="register_password"></asp:textbox>
confirm password: <asp:textbox runat="server" textmode="password" id="confirmpassword" cssclass="register_password"></asp:textbox></span>
</wizardsteps>
... ...
</asp:createuserwizard>
在使用上面代碼時,請注意系統默認定義的id,例如用戶名使用textbox的id只能是username,密碼使用的textbox的id只能夠是password。...
當然,你可以到msdn查看createuserwizard 更多的預定義id。
3)自定義id
可能用些人又不滿足了,我為什么必須使用微軟預定義的id,我就想讓用戶的id為myname,密碼id為mypassword,如果你使用自定義的id,系統將不能夠識別,這時你就需要自己獲取myname和mypassword的text值了。具體處理較為繁瑣。因為你需要做如下步驟
1>獲取用戶名
2>獲取密碼
3>連接數據庫
4>將輸入寫入數據庫
5> 關閉數據庫
可以看到,不使用系統預定義的功能,你的工作量將大幅度增加。具體此處就不再說明了。
新聞熱點
疑難解答
圖片精選