开发者

Why is a postback not being triggered?

开发者 https://www.devze.com 2023-02-16 07:25 出处:网络
I have a simple web form, but when I submit the button postback is always false. This should all happen on the same page.

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[...].

0

精彩评论

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