English 中文(简体)
无法将 Ajax Control Toolkit. maskedEdit Extender 类型的对象投入系统类型 。 Web.UI.Web controls. TextBox 。
原标题:Unable to cast object of type AjaxControlToolkit.MaskedEditExtender to type System.Web.UI.WebControls.TextBox

我使用这个:http://www.asp.net/ajaxlibrary/Ajax ControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx

In a column I have multiple textboxes binded to some columns from database. My goal is to get the value from those textboxes that are maskedit. Since there are 4 controls in the column I m trying to get the values like this:

String firstTXT = ((TextBox)(row.Cells[5].Controls[1])).Text;
String SecondTXT = ((TextBox)(row.Cells[5].Controls[2])).Text;

I can get the value from the firsttexbox without any error ( but it s also masked ) . and when I Try to get from the second I get : Unable to cast object of type AjaxControlToolkit.MaskedEditExtender to type System.Web.UI.WebControls.TextBox .

有解决的机会吗? 谢谢。

问题回答

显然,单元格中的第三个控件是 MaskedEditExtender ,该控件将增强第一个文本框。根据您的标记,您可能想要取而代之的是第四个控件:

string secondTXT = ((TextBox) row.Cells[5].Controls[3]).Text;

或者,最好把id 属性赋予您的文本框,并使用 < a href="http://msdn.microsoft.com/en-us/library/486wc64h.aspx" rel=“nofollow” >Find control( )来获取它们:

string firstTXT = ((TextBox) row.Cells[5].FindControl("firstID")).Text;
string secondTXT = ((TextBox) row.Cells[5].FindControl("secondID")).Text;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签