Ronald
Ronald

Reputation:

initialize html controls in asp.net

If I have an html input "<input id="score1" type="text" value=""/>" and want to initialize it on the c# page load, but I don't want to use asp controls.How do I do it?

Thanks

Upvotes: 1

Views: 560

Answers (4)

Joel Coehoorn
Joel Coehoorn

Reputation: 416049

<input id="score1" type="text" runat="server" value=""/>

Then in your page's load event:

score1.Value = "some value";

Upvotes: 3

John Boker
John Boker

Reputation: 83719

You could set a property on the page codebehind, the access the property on the page

public class MyPage
{
    public string InputDefaultContent { get; set; }

    private void Page_Load(object s, EventArgs e)
    {
        InputDefaultContent = "Blah";
    }
}

then on the page

<input type="text" value="<%= InputDefaultContent %>" />

Upvotes: 2

Jimmy
Jimmy

Reputation: 91482

<input type='text' value='default value' />

Upvotes: 0

Matthew Groves
Matthew Groves

Reputation: 26169

You can use server-side plain HTML controls, by just using runat="server".

For instance:


<input type="text" runat="server" id="myTextBox" />

// ...and then in the code-behind...

myTextBox.Value = "harbl";

Upvotes: 5

Related Questions