tags:

views:

122

answers:

4

Hi,

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  A: 

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";
mgroves
...and for the record these are typically known as "Hybrid Controls" in the ASP.NET realm. Not quite HTML controls, not quite Web Controls.
Dillie-O
I've never seen them referred to as hybrid controls. They've always been HTML Controls.
John Saunders
I like the "Hybrid Controls" term though
mgroves
You can like it, but what if nobody else uses it?
John Saunders
*shrug*...just seems like a good term is all...
mgroves
Never heard the Hybrid Controls either, but it is a good term. Don't think I'll "switch" from saying HTML Controls though.
Jesper Karsrud
A: 
<input type='text' value='default value' />
Jimmy
A: 

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 %>" />
John Boker
+2  A: 

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

Then in your page's load event:

score1.Value = "some value";
Joel Coehoorn