使用 CreateUserWizard 时未将对象引用设置为对象实例错误

2024-01-12

当我点击 CreateUserWizard 控件的“下一步”按钮时,出现错误 -“对象引用未设置为对象的实例”。我检查了我的代码,没有将任何变量保留为空。但我仍然可以不解决这个错误。

 Source Error: 

    Line 29:         object UserGUID = User.ProviderUserKey;
    Line 30: 
    Line 31:         DataSource.InsertParameters.Add("UserId", UserGUID.ToString()); //this is the line that caused the error
    Line 32: 
    Line 33:         DataSource.Insert();

This is my html code file: 

 <form id="form1" runat="server">
    <div>
        <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 
            OnCreatedUser="CreateUserWizard1_CreatedUser" CreateUserButtonText="Next" 
            FinishCompleteButtonText="Create User" Height="330px" 
            Width="512px">
            <WizardSteps>

                <asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server" >
                <ContentTemplate>
                    <table>
                        <tr>
                            <th>User Information</th>
                        </tr>
                        <tr>
                            <td>Username:</td>
                            <td class="style2">
                                <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 class="style2">
                                <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 class="style2">
                                <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 class="style2">
                                <asp:TextBox runat="server" ID="Email" />
                                  <asp:RequiredFieldValidator ID="RequiredFieldValidator16" runat="server" ControlToValidate="Email" 
                                      ErrorMessage="Email required."></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td>Question:</td>
                            <td class="style2">
                                <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 class="style2">
                                <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>


                </ContentTemplate>
                </asp:CreateUserWizardStep>
                <asp:WizardStep ID="CreateUserWizardStep0" runat="server" Title="User Details">
                    <table>
                        <tr>
                            <th>Billing Information</th>
                        </tr>
                        <tr>
                            <td>Name:</td>
                            <td class="style1">
                                <asp:TextBox runat="server" ID="CustName" />
                                  <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator18" ControlToValidate="CustName"
                                     ErrorMessage="Name is required."  />
                                     </td>
                        </tr> 
                        <tr>
                            <td>Contact Number:</td>
                            <td class="style1">
                                <asp:TextBox runat="server" ID="CustNum"  />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator19" ControlToValidate="CustNum"
                                     ErrorMessage="Contact num is required."  />
                            </td>
                        </tr>   
                        <tr>
                            <td>Role:</td>
                            <td class="style1">
                                <asp:DropDownList ID="CustRole" runat="server" AutoPostBack="True" Height="16px" 
                                    Width="123px">
                                    <asp:ListItem></asp:ListItem>
                                    <asp:ListItem>Bride</asp:ListItem>
                                    <asp:ListItem>Groom</asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator20" ControlToValidate="CustRole"
                                     ErrorMessage="Role is required." />
                            </td>
                        </tr>                
                        <tr>
                            <td>
                                Status:</td>
                            <td class="style1">
                                <asp:DropDownList ID="CustStatus" runat="server" AutoPostBack="True" 
                                    Height="17px" Width="121px">
                                    <asp:ListItem></asp:ListItem>
                                    <asp:ListItem>Status A</asp:ListItem>
                                    <asp:ListItem>Status B</asp:ListItem>
                                    <asp:ListItem>Status C</asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator15" runat="server" ControlToValidate="CustStatus"
                                    ErrorMessage="Status is required."/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;</td>
                            <td class="style1">
                                &nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                                Partner&#39;s Name:</td>
                              <td class="style1">
                                <asp:TextBox runat="server" ID="PName"  />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator5" ControlToValidate="PName"
                                     ErrorMessage="PName is required."  />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Partner Email:</td>
                            <td class="style1">
                                <asp:TextBox runat="server" ID="PEmail"  />

                            </td>
                        </tr>
                        <tr>
                            <td>
                                PRole:
                            </td>
                            <td class="style1">
                                <asp:DropDownList ID="PRole" runat="server" AutoPostBack="True" Height="16px" 
                                    Width="123px">
                                    <asp:ListItem></asp:ListItem>
                                    <asp:ListItem>Bride</asp:ListItem>
                                    <asp:ListItem>Groom</asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator7" ControlToValidate="PRole"
                                     ErrorMessage="PRole is required." />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Wed Date:
                            </td>
                            <td class="style1">
                                <cc1:DatePicker ID="WedDate" runat="server" CalendarDate="" 
                                    TextCssClass="" />
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator17" runat="server" ControlToValidate="WedDate"
                                    ErrorMessage="Wedding date required"/>
                            </td>
                        </tr>
                    </table>
                </asp:WizardStep>

                <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
                    <ContentTemplate>
                        <table>
                            <tr>
                                <td align="center" colspan="2">
                                    Complete</td>
                            </tr>
                            <tr>
                                <td>
                                    Your account has been successfully created.</td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2">
                                    <asp:Button ID="ContinueButton" runat="server" CausesValidation="False" 
                                        CommandName="Continue" Text="Continue" ValidationGroup="CreateUserWizard1" />
                                </td>
                            </tr>
                        </table>


                       <asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"
                        InsertCommand="INSERT INTO [UserDetails] ([UserId], [CustName], [CustNum], [CustRole], [CustStatus], [PName], [PEmail], [PRole], [WedDate]) VALUES (@UserId, @CustName, @CustNum, @CustRole, @CustStatus, @PName, @PEmail, @PRole, @WedDate)"
                        ProviderName="<%$ ConnectionStrings:ASPNETDBConnectionString1.ProviderName %>">
                        <InsertParameters>
                            <asp:ControlParameter Name="CustName" Type="String" ControlID="CustName" PropertyName="Text" />
                            <asp:ControlParameter Name="CustNum" Type="String" ControlID="CustNum" PropertyName="Text" />
                            <asp:ControlParameter Name="CustRole" Type="String" ControlID="CustRole" PropertyName="Text" />
                            <asp:ControlParameter Name="CustStatus" Type="String" ControlID="CustStatus" PropertyName="Text" />
                            <asp:ControlParameter Name="PName" Type="String" ControlID="PName" PropertyName="Text" />
                            <asp:ControlParameter Name="PEmail" Type="String" ControlID="PEmail" PropertyName="Text" />
                            <asp:ControlParameter Name="PRole" Type="String" ControlID="PRole" PropertyName="Text" />
                            <asp:ControlParameter Name="WedDate" Type="String" ControlID="WedDate" PropertyName="Text" />
                        </InsertParameters>

                    </asp:SqlDataSource>

                    </ContentTemplate>
                </asp:CompleteWizardStep>
            </WizardSteps>

        </asp:CreateUserWizard>
        <br />
    </div>

This is the code behind: 

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web.Security;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class Register : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        TextBox UserName=
        (TextBox)CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName");

        SqlDataSource DataSource =
        (SqlDataSource)CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo");

       MembershipUser User = Membership.GetUser(UserName.Text);

        object UserGUID = User.ProviderUserKey;

        DataSource.InsertParameters.Add("UserId", UserGUID.ToString());  //the error lies at here

        DataSource.Insert();

    }
    }

我已经检查过我的代码,我没有留下任何我的 变量为空。但我仍然无法解决这个错误。

您还没有检查所有变量,否则不会发生此错误。

您是否检查过 DataSource 以确保找到 SqlDataSource? DataSource的InsertParameters属性确保它不为null? UserGUID 确保它不为空?

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 CreateUserWizard 时未将对象引用设置为对象实例错误 的相关文章

  • 如何指定CMAKE外部项目的编译器?

    我使用ExternalProject Add 包含一个外部项目 我想要的是能够做到 cmake DCMAKE CXX COMPILER
  • 如何在C编程中获取当前时间(以毫秒为单位)[重复]

    这个问题在这里已经有答案了 可能的重复 如何使用 ANSI C 测量以毫秒为单位的时间 https stackoverflow com questions 361363 how to measure time in milliseconds
  • 将 LINQ to Entities 查询中的每个项目转换为接口的最佳方法是什么?

    我有一个实现 IUser 的实体对象 User IQueryable
  • 在 C 中声明和初始化数组

    C 有没有办法先声明然后初始化数组 到目前为止 我一直在初始化一个这样的数组 int myArray SIZE 1 2 3 4 但我需要做这样的事情 int myArray SIZE myArray 1 2 3 4 在 C99 中 您可以使
  • ResourceDictionary 源中的 Uri 语法(通用 Windows 平台)

    我正在迁移我的Windows 8 1项目到Windows 10 通用 Windows 平台 这时我被拦住了ResourceDictionary改变在UWP 为了简单起见 我有包含 2 个项目的 Windows 8 1 解决方案 App pr
  • F# 内联如何工作?

    对于 F 我的理解是您可以使用 inline 关键字在调用站点执行类型专门化 那是 val inline a gt b gt c when a or b static member a b gt c 约束条件是 a or b必须有一个静态成
  • 按位非运算符

    为什么要按位运算 0 打印 1 在二进制中 不是0应该是1 为什么 你实际上很接近 在二进制中 不是0应该是1 是的 当我们谈论一位时 这是绝对正确的 然而 一个int其值为0的实际上是32位全零 将所有 32 个 0 反转为 32 个 1
  • 了解 MVC-5 身份

    我创建了一个新的ASP NET MVC 5申请与Individual User Accounts然后更新了所有的Nuget packages在解决方案中 现在我尝试遵循一些教程中显示的一些指南 但遇到了一些问题 第一个是一个名为Applic
  • “volatile void function( ... )” 做了什么?

    我见过从语法角度来看 C 函数中 volatile 关键字有多少种用法 https stackoverflow com questions 7643528 how many usage does volatile keyword have
  • 在标准库中静态链接时如何支持动态插件?

    假设一个应用程序myapp exe是使用构建的g 它使用标志 static libstdc 这样就可以安装在没有环境的情况下libstdc so myapp exe还添加了对某些功能的插件支持plugf可以通过动态加载dlopen来自共享库
  • 使用 for 循环创建链表

    这是我的结构 struct ListItem int data struct ListItem next 假设链表的第一个节点的 data 0 我想编写一个 for 循环来创建大小为 5 的链表 但我不知道如何工作 我尝试了以下方法 int
  • 复杂的 C 声明

    我刚刚在互联网上浏览了一些代码 发现了这个 float foo SIZE SIZE 我如何阅读这份声明 是否有一套特定的规则来阅读如此复杂的声明 我有一段时间没做这个了 从 开始foo然后向右走 float foo SIZE SIZE fo
  • 带有 Unicode 字符的主机名在 Windows 8 中有效

    Uri CheckHostName 回报UriHostNameType Unknown到处都是 但在 Windows 8 上 它又回来了UriHostNameType Dns 为什么突然间带有 Unicode 西里尔字符的主机名在 Wind
  • 一个对大文件有效的轻量级 XML 解析器?

    我需要解析潜在的巨大 XML 文件 所以我猜这排除了 DOM 解析器 是否有任何优秀的 C 轻量级 SAX 解析器 在占用空间上可与 TinyXML 相媲美 XML的结构非常简单 不需要诸如命名空间和DTD之类的高级东西 只是元素 属性和
  • 如何最好地为 Visual Studio 2017 构建的 CMake C++ 项目设置输出目录?

    我使用 Visual Studio 2017 使用 vcxproj 文件构建 C 桌面项目 我喜欢默认行为 其中输出目录是项目下面的子目录 例如 myproj sln myproj vcxproj x64 myproj release my
  • 在发送传出请求之前将新的 SoapClient 绑定到特定 IP 地址

    假设应用程序所在的计算机具有 SoapClient 具体来说 我正在使用 Microsoft Web Service3 Messaging SoapClient 它通过发送传出请求并获取 SoapEnvelope 作为回报 完善的流程 与远
  • Azure Function App Azure 服务总线触发器触发两次

    我使用带有服务总线触发器的 Azure Function Apps 来读取服务总线并对服务总线消息的内容执行操作 服务总线接收 JSON 序列化对象 然后将 JSON 消息反序列化回 Function App 中的对象 然而 由于某种原因
  • MonoGame 中的 ContentLoadException

    我一直在尝试使用 Xamarin Studio 在 MonoGame 中加载纹理 我的代码设置如下 region Using Statements using System using Microsoft Xna Framework usi
  • 字符串常量之前应有非限定 ID

    我目前正在编写一个 C 应用程序 它与 math h 结合实现了振荡器 我拥有的代码应该可以很好地用于该应用程序 尝试编译目标文件 但是我遇到编译器错误 很可能与语法 等有关 我认为这与命名空间有关 错误 终端输出 User Name Ma
  • 为什么 32 位 .NET 进程的引用类型的最小大小为 12 字节

    我正在读专业 Net 性能 https rads stackoverflow com amzn click com 1430244585本书有关参考类型内部结构的部分 它提到 对于 32 位 net 进程 引用类型具有 4 字节的对象头和

随机推荐

  • 在 SSRS 查询字符串中传递多值参数的值

    我有两个使用 SSRS 2005 构建的报告 第一个报告设置为在单击特定字段时导航到第二个报告 我在文本框的 跳转到 URL 属性中使用类似于以下内容的表达式 javascript void window open http server
  • 如何下载需要用户名和密码的网页?

    例如 我想在插入用户名和密码后下载此页面 http forum ubuntu it org 我尝试过 wget 但不起作用 有 python 的解决方案吗 您可以使用这些用户名和密码进行测试 username johnconnor pass
  • GetView 与。自定义 CursorAdapter 中的 BindView?

    所以我正在看这个视频http www youtube com watch v N6YdwzAvwOA http www youtube com watch v N6YdwzAvwOARomain Guy 正在展示如何使用getView 方法
  • 创建从 C 到 C# 的混合模式 C++ 桥接器?

    我希望有人能帮助我解决这个问题 我主要是一名 C 开发人员 所以我的 C和C 技能很差 我有一个本机 C dll 它是一个插件 更大的应用 我在Linux上为Windows交叉编译这个dll 使用海湾合作委员会 在本机 dll 中 当我创建
  • 资产文件夹中的 Pdf 文件无法在第三方应用程序中打开

    你好 我是 android 新手 我有一些 PDF 文件存在于该路径中asset pdf example pdf 当我尝试使用此代码创建 PDF 文件时 Intent intent new Intent Intent ACTION VIEW
  • 如何动态构建 Perl 正则表达式?

    我有一个 Perl 脚本 它使用 File Next files 遍历目录层次结构 它只会返回以 avi flv mp3 mp4 和 wmv 结尾的脚本文件 它还会跳过以下子目录 svn 和任何以 frames 结尾的子目录 这是在file
  • 带 PyGTK 崩溃的多线程 Gstreamer (xcb_xlib_threads_sequence_lost)

    我知道不应该从其他线程更新 UIgtk 或面临后果 但我不确定在使用时如何避免这种情况gstreamer 我的应用程序在视频流初始化期间有时会崩溃 并出现以下投诉 xcb Unknown sequence number while proc
  • 处理对象字段验证的最佳方法 => Either / Try (scala 2.10) / ValidationNEL (scalaz)

    让我们假设一个使用构建器模式构造的对象 这个构建器模式将包含一个build方法侧重于字段验证 然后转换为目标类型 该验证可以使用以下方式实现 Either FailureObject TargetObject type Try Target
  • CSS 冲突样式表

    我有两个样式表 它们在几个方面相互冲突 因为我使用 5 个 6 个 有时甚至 9 个或 10 个完整的插件 每个插件都有三四个样式表 以及我自己的样式表 所以到处都会出现冲突 解决这个问题的最佳方法是什么 是进入并修改所有插件的选择器的唯一
  • Delayed_jobs 保存已完成的作业

    是否有一个参数可以传递给delayed job 以防止它从delayed jobs 表中删除已完成的作业 有点像destroy failed jobs但对于已完成的工作 有任何想法吗 扩展 jefflunt的答案 我添加了一个迁移来创建一个
  • 检查文本框是否为空

    我有一个文本框 我想检查它是否为空 哪种方式更好 if TextBox Text Length 0 or if TextBox Text 你应该使用String IsNullOrEmpty https msdn microsoft com
  • 即使使用 Polyfill,IE 也不支持 forEach。

    我已将 forEach polyfill 添加到 JavaScript 文件的顶部 但 Internet Explorer 仍然说它不支持该功能 我基本上想循环 querySelector 的结果 但是我确实在脚本中的一些其他数组对象上使用
  • Node JS 匿名函数和回调

    请有人帮助我 我阅读了大量的 javascript 文档并摆弄了 javascript 我能够使用这些函数 但我不太明白这里的基本句法爵士乐 var http require http http createServer function
  • 监控个别窗口服务的表现

    我有 7 个 Windows 服务 我想监控各个服务的性能 例如处理器使用情况 内存使用情况等 如果我使用 perfmon 它会提供整个系统 但不会提供单个服务 谁能建议我如何监控个别服务的性能 Perfmon 可以监控各个进程 只需在 添
  • 如何设置Web服务客户端的请求时间(java)

    我正在开发一个基于桌面的应用程序 就像投递箱一样 我有一个功能downloadFile long fileId 为我从网络下载文件 应用程序的桌面端是用java编写的 其中网络服务是用 Net编写的 我已经使用 netbeans 生成了 W
  • 为什么我们在 junit 测试中使用 Mockitojunitrunner 类? [复制]

    这个问题在这里已经有答案了 我是mockito框架的新手 对此我有一个非常基本的问题 为什么我们要使用MockitoJunitRunner 类在我们的junit测试课中 我还发现以下两点与此相关 但无法得到它 任何人都可以详细解释以下两点
  • 将 NSString 转换为 NSDate

    我有日期字符串 2010 年 10 月 11 日星期一 如何从中创建一个 NSDate 对象 然后从中获取不同的组件 例如日 月 日期 年 请注意 该字符串的格式 区域设置可能会在运行时更改 使用 NSDateFormatter 创建 NS
  • 使用 AVMutableComposition 进行精确计时

    我正在尝试使用 AVMutableComposition 在精确的时间播放一系列声音文件 当视图加载时 我创建了一个合成 目的是在 1 秒内均匀地播放 4 个声音 声音的长短并不重要 我只想在 0 0 25 0 5 和 0 75 秒时触发它
  • 创建 ClusterRole 作为默认计算服务帐户失败并出现额外权限错误

    我正在尝试在私有集群中创建一个新的 ClusterRole 我通过 Jumpbox 对其进行管理 但始终遇到 禁止 尝试授予额外权限 错误 我使用 gcloud 作为默认计算服务帐户进行身份验证 并且该帐户具有 Kubernetes Eng
  • 使用 CreateUserWizard 时未将对象引用设置为对象实例错误

    当我点击 CreateUserWizard 控件的 下一步 按钮时 出现错误 对象引用未设置为对象的实例 我检查了我的代码 没有将任何变量保留为空 但我仍然可以不解决这个错误 Source Error Line 29 object User