I have a simple web form, but when I submit the button postback is always false. This should all happen on the same page.
<form runat="server" class="frm" method="post" action="">
<span><input type="radio" name="options" value="Milk" /><label>Option 1</label></span>
<span><input type="radio" name="options" value="Butter" /><label>Option 2</label></span>
<span><input type="radi开发者_开发百科o" name="options" value="Cheese" /><label>Option 3</label></span>
<span><input type="radio" name="options" value="Milk" /><label>Option 4</label></span>
<span><input type="radio" name="options" value="Butter" /><label>Option 5</label></span>
<span><input type="radio" name="options" value="Cheese" /><label>Option 6</label></span>
<input type="submit" name="submit" value="vote" />
</form>
*Button Code *
<asp:Button ID="loginBtn" runat="server" Text="vote" OnClick="Login" />
As Noon Silk said, you need to use server side controls, but you also need to use the asp.net mechanism on the form tag; see example code below. Notice the form tag has a 'runat="server"' attribute rather than a method and action:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="button" runat="server" />
</div>
</form>
</body>
</html>
Because you're not using the .net controls; you are just doing it manually.
You'd need to use an ASP.NET button, like so:
<asp:Button runat="server" ID="btnSubmit" ... />
And same for your inputs, if you want to be able to access them through txtFoo.Text
. Of course, if you don't, you can still access everything through Request[...]
.
精彩评论