开发者

Access to HTML Button in aspx.cs (Code Behind)

I have a doubt: if开发者_如何学运维 I write a HTML button in source code, how can I access it in the aspx.cs, Can you provide me some examples?


If you set an ID on the button and set the runat attribute to server you'll able to get it from code-behind with FindControl.

HTML:

<input type="button" id="myButton" runat="server" />

Code-behind (C#):

Button myButton = (Button) FindControl("myButton");

Also, instead of using html you can use the defined ASP-tag for buttons...

<asp:Button ID="myButton" runat="server" />

Now you have the help of auto-completion etc. in the code-behind:

myButton.Text = "My Button";


If you add the runat="server" and id="mybutton" attributes to the button then you can access it in your code via the generated myButton variable.


if you don't want to use component ASP:XXX, you can use HTML Controls see below: HTML

<button  ID="cmdbutton" runat="server" class="glyphicon glyphicon-barcode btn btn-default btn-lg right" type="button">Sua boleta já está disponível</button>

See, I used runat="server"in HTML control. Code-behind(VB.NET)

Dim vloControl As System.Web.UI.HtmlControls.HtmlButton
vloControl = CType(e.Item.FindControl("cmdButton"),System.Web.UI.HtmlControls.HtmlButton)
vloControl.Attributes.Add("OnClick", "CallFunJs();")


You can access it by giving it an ID and adding the runat="server" attribute to the html button element.

You can then access it like any other server control, using the ID that you set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜