输入到datalist内部的Textbox的值未分配 [英] Value entered into Textbox inside datalist is not assigning

查看:77
本文介绍了输入到datalist内部的Textbox的值未分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Button18_click上遇到以下异常:



App_Web_cdebfrfo.dll中出现'System.NullReferenceException'类型的异常,但未在用户代码中处理



附加信息:对象引用未设置为对象实例





我在datalist中的文本框代码:

I get the following exceptions at Button18_click:

An exception of type 'System.NullReferenceException' occurred in App_Web_cdebfrfo.dll but was not handled in user code

Additional information: Object reference not set to an instance of an object


My code for textbox inside a datalist:

<asp:TextBox Id="TB2" runat="server" Text="" Width="24" OnTextChanged="TB2_TextChanged" MaxLength="6"

Height="12"     BorderStyle="Groove">
</asp:TextBox>

<asp:Button ID="Button18" runat="server" ForeColor="White"  onclick="Button18_Click"

         BackColor="Teal" Font-Size="small"

 style="z-index: 1;font-family:Sans-Serif; height:22px;  font-weight:900; "

 Text="Add to cart" />







protected void Button18_Click(object sender, EventArgs e)
   {
       string ss = Convert.ToString(Datalist1.FindControl("TB2").ToString());
  }

推荐答案

找不到TB2控件。我建议放置断点并调试它也许你有一个额外的控件,它是文本框的父级。FindControl不会一直走到树下。因此,您可能需要执行Datalist1.Controls [0] .FindControl(TB2)。调试它,你应该能够找到它。
It can't find the TB2 control. I would recommend putting breakpoint and debug it. Perhaps you have an additional control that is the parent of the textbox. FindControl does not go all the way down the tree. So, you may need to do Datalist1.Controls[0].FindControl("TB2") for example. Debug it and you should be able to find it.


这篇关于输入到datalist内部的Textbox的值未分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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