这是页面指令:
<%@ Page Title="Edit Condition" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ManageCondition.aspx.cs" Inherits="Backyard_Cures.ManageCondition" %>
该行抛出了这个运行时错误:
Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.TextBox'
aspx文件:
<%@ Page Title="Edit Condition" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ManageCondition.aspx.cs" Inherits="Backyard_Cures.ManageCondition" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<link href="Styles/ManageCondition.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="condition_block">
<div class="input">
<div class="label">Title</div>
<asp:TextBox Text="" CssClass="textbox" ID="Title" runat="server"></asp:TextBox>
</div>
<div class="help">Text</div>
</div>
<br />
<div class="condition_block">
<div class="input">
<div class="label">Description</div>
<asp:TextBox Text="" CssClass="textbox" ID="Description" runat="server"></asp:TextBox>
</div>
<div class="help">Text</div>
</div>
<br />
<div class="condition_block">
<div class="input">
<div class="label">Condition Tags</div>
<asp:TextBox Text="" CssClass="textbox" ID="Tags" runat="server"></asp:TextBox>
</div>
<div class="help">Text</div>
</div>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</asp:Content>
文件后面的代码:
namespace Backyard_Cures
{
public partial class ManageCondition : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Condition new_condition = new Condition();
new_condition.Title = Title.Text;
new_condition.Content = Description.Text;
int new_conditionID = Backyard_Cures.AccessLayer.InsertCondition(new_condition);
Response.Redirect("~/ViewCondition.aspx?ConditionID=" + new_conditionID, true);
}
}
}
后面的主文件代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
答案 0 :(得分:0)
该页面有一个名为Title的属性,您的文本框ID为Title。 您需要更改文本框的ID