Reputation: 87
Good afternoon, I'm learning aspnet, and web development, and I'm having a hard time understanding how I can call a certain postback function ... could anyone please answer me how do I do this...
codigo:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
btnTest.Value = hid.Value;
}
protected void function2()
{
//param other function here
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>test postback</title>
<script type="text/javascript">
function doTest() {
var nome = document.getElementById("nome");
var hid = document.getElementById("hid");
hid.value = nome.value;
return true;
}
</script>
</head>
<body>
<form id="form1" name="form1" runat="server">
<div>
<input type="text" id="nome" value="%%" name="nome" runat="server"/>
<input type="hidden" name="hid" id="hid" value="" runat="server" />
<input type="submit" id="btnTest" runat="server" name="btnTest" value="button" onclick="doTest();" />
</div>
</form>
</body>
</html>
Upvotes: 0
Views: 428
Reputation: 4250
If you want to use html controls you have to use the onserverclick
method:
<input runat="server" type="button" onserverclick="ButtonClick"/>
In you code behind:
protected void ButtonClick(object sender, EventArgs e)
{
//Your code goes here
}
You can also use the built in WebControls:
<asp:Button runat="server" ID="btnTest" OnClick="ButtonClick"/>
The code behind would be the same.
Upvotes: 1