1

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

4 Answers 4

5

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";
Sign up to request clarification or add additional context in comments.

5 Comments

...and for the record these are typically known as "Hybrid Controls" in the ASP.NET realm. Not quite HTML controls, not quite Web Controls.
I've never seen them referred to as hybrid controls. They've always been HTML Controls.
I like the "Hybrid Controls" term though
You can like it, but what if nobody else uses it?
Never heard the Hybrid Controls either, but it is a good term. Don't think I'll "switch" from saying HTML Controls though.
3

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

Then in your page's load event:

score1.Value = "some value";

Comments

2

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 %>" />

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.