1
我不知道爲什麼我出現此錯誤,代碼正在工作並且運行得更早。我試圖通過按鈕更新用戶的電子郵件。它工作得很好,但現在由於某種原因,它不斷給我的錯誤: 「對象引用不設置到對象的實例 線34:EmailTextBox.Text = u.Email」獲取'對象引用未設置爲對象的實例'錯誤..vb
已在此刮傷了現在幾個小時,任何人都有一個想法可能是什麼?
我aspx.vb代碼:
Public Class _Default
Inherits System.Web.UI.Page
Dim u As MembershipUser
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
u = Membership.GetUser(User.Identity.Name)
If Not IsPostBack Then
EmailTextBox.Text = u.Email
End If
End Sub
Public Sub UpdateEmailButton_OnClick(ByVal sender As Object, ByVal args As EventArgs)
Try
u.Email = EmailTextBox.Text
Membership.UpdateUser(u)
Msg.Text = "User e-mail updated."
Catch e As System.Configuration.Provider.ProviderException
Msg.Text = e.Message
End Try
End Sub
ASPX代碼:
<h3>Update E-Mail Address for <%=User.Identity.Name%></h3>
<asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />
<table cellpadding="3" border="0">
<tr>
<td>E-mail Address:</td>
<td><asp:TextBox id="EmailTextBox" MaxLength="128" Columns="30" runat="server" /></td>
<td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
ControlToValidate="EmailTextBox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td></td>
<td><asp:Button id="UpdateEmailButton"
Text="Update E-mail"
OnClick="UpdateEmailButton_OnClick"
runat="server" /></td>
</tr>
</table>
感謝您的回答有所幫助,這是由於在用戶登錄之前顯示的用戶成員身份數據解決了問題。 :) – 2012-01-08 16:51:56