user2538192
user2538192

Reputation: 21

Access HTML page in C#

Basically I have two files: details.html details.cs

I would like to use details.cs to write values to details.html but the html textbox still stays the same.

details.html

<%@ Page Language="C#" 
AutoEventWireup="true" 
CodeBehind="details.cs" 
Inherits="Details.DetailsHTML" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form>
<input id="txt_details" type="text" name="txt_details" runat="server"/>
</form>
</body>
</html>

details.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using System.Data;

namespace Details
{
    public partial class DetailsHTML : Page
    {
        //Declare controls used
        protected System.Web.UI.HtmlControls.HtmlInputText txt_details;

        protected void Page_Load(object sender, EventArgs e)
        {
            string strValue = Page.Request.Form ["txt_details"].ToString();
            strValue = "test";
        }
     }

}

Upvotes: 2

Views: 863

Answers (3)

Adil
Adil

Reputation: 148180

You can not access control in .html from .cs file. You are trying to use aspx page as you are inherting from Page class but naming .html, you are problably not using visual studio. Use details.aspx and details.aspx.cs. If you do not have Visual Studio then you can download free express version from here. This link explains how to create web application project using visual studio. The article Creating a Basic Web Page with Code Separation in Visual Studio will help you in creating the web page and access html control on server side.

txt_details.Value = "your value";

Upvotes: 1

Jose Rodriguez
Jose Rodriguez

Reputation: 10192

You can acess by a name of control eg:

txt_details.Value = "Test"

Upvotes: 0

Venkata Krishna
Venkata Krishna

Reputation: 15112

txt_details.Value = "test";

This should help

Upvotes: 0

Related Questions