我得到一个错误就像对象引用没有设置为对象的实例。 [英] Im getting an error as like object reference not set to an instance of an object.

查看:80
本文介绍了我得到一个错误就像对象引用没有设置为对象的实例。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:FormView ID="fvFileUpload" runat="server" Width="418px">
        <ItemTemplate>
            <asp:Label ID="lblFileId" Text="File ID" runat="server" Width="120px" />
            <asp:TextBox ID="txtFileID" runat="server" />
            <br />
            <asp:Label ID="lblFileName" Text="File Name" runat="server" Width="120px" />
            <asp:TextBox ID="txtFileName" runat="server" />
            <br />
            <asp:Label ID="lblFileKey" Text="File Key" runat="server" Width="120px" />
            <asp:TextBox ID="txtFileKey" runat="server" />
            <br />
            <asp:Label ID="lblUpload" Text="File Upload" runat="server" Width="120px" />
            <asp:FileUpload ID="fupload" runat="server" />
            <br />
            <asp:Label ID="lblUplodedBy" Text="File Owner" runat="server" Width="120px" />
            <asp:TextBox ID="txtOwner" runat="server" />
            <br />
            <br />
            <asp:Button ID="btnReq" Text="Requset to Auditor" runat="server" OnClick="btnReq_Click" />
            <asp:Button ID="btnClear" Text="Clear" runat="server" Height="25px" OnClick="btnClear_Click" Width="150px" />
        </ItemTemplate>
    </asp:FormView>







这是我的代码背后代码






This is my code behind code

private void FileIDGen()
   {
       string FileID = crudobj.SelectFileId();
       ((TextBox)fvFileUpload.FindControl("txtFileID")).Text = FileID; // im getting error here but im getting FileId string value as File1. the problem occurs when it tries to assign that value to the textbox
   }

推荐答案

当它尝试将该值分配给文本框时出现问题

因为它找不到具有IDtxtFileID的控件作为FormView的子项 - 所以它返回一个空值。



尝试使用Page.FindControl方法而不是Control.FindControl,或者使用调试器来查看你拥有的内容。我们可以为您解决这个问题 - 我们无法访问您的代码!
"the problem occurs when it tries to assign that value to the textbox"
Because it can't find a control with the ID "txtFileID" as a child of the FormView - so it returns a null value.

Try the Page.FindControl method instead of the Control.FindControl, or use teh debugger to look at exactly what you have. We can;t solve this for you - we don't have any access to your code!


试试这个.. :)



Try this.. :)

TextBox txtproFileID = (TextBox)fvFileUpload.FindControl("txtFileID");
txtproFileID.Text=FileID;


这篇关于我得到一个错误就像对象引用没有设置为对象的实例。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆