Noobie
Noobie

Reputation: 107

Error while converting a textbox control in gridview in ASP.NET 3.5

I have a very simple command, where I am just finding the textbox in the footer of the gridview and based on its value I am assigning some value.

if (!string.IsNullOrWhiteSpace(((TextBox)gvSession.FooterRow.FindControl("tbSessionAdd")).Text))
                OnlinePlatform = "ZoomMeeting";

The error is :

Compiler Error Message: CS0030: Cannot convert type 'System.Web.UI.Control' to 'TextBox'

The website works fine on another server but it is giving this error on the local server. So I feel that issue might have to do with some other settings. So any idea or suggestion will be appreciated.

if I comment this part out it start giving error on forecolor and tooltips also.

Like this:

if (!IsValidSessionTime(startTime, endTime, out message))
        {
            tbStartTimeAdd.BackColor = Color.Red;
            tbStartTimeAdd.ToolTip = message;
        }

with error message

Compiler Error Message: CS1061: 'TextBox' does not contain a definition for 'BackColor' and no extension method 'BackColor' accepting a first argument of type 'TextBox' could be found (are you missing a using directive or an assembly reference?)

Upvotes: 0

Views: 27

Answers (1)

Albert D. Kallal
Albert D. Kallal

Reputation: 49329

Do you have a winforms reference in your project (not web forms, but winforms).

Say like this:

Using System.Windows.Forms

So, best guess is you have some reference to a windows program, or Windows.Forms, and that's not only going to result in a conflict, but the incorrect type of TextBox.

So, I would check if you have some incorrect reference here.

Perhaps edit your question, and include the list of "using" statements at the start of the code block, and remove any stray references to windows forms.

And it's also possible that you not using a ASP.NET TextBox in your GridView, but perhaps a standard HTML text box.

Upvotes: 0

Related Questions