c# - 单选按钮值为空

标签 c# jquery html css

我正在尝试获取单击的单选按钮的值,但到目前为止该值为空。下面的代码发生了几件事: 1)单击按钮时,应将单选按钮向左移动。 2) 我需要获取单击哪个单选按钮的值

第一部分有效,但我无法获得第二部分。这是我的代码:

<script> 
    $(document).ready(function(){
        $("#form1").click(function(){
            $("#list_of_btns").animate({left: '-150px'});
        });
    });
</script> 

//this is the form for radio button...it must be centered to middle of the page

<div id="list_of_btns" style="padding-top: 80px; position:fixed;">
        <div class="row" style="position:fixed;">
            <div class="col-md-8 col-md-offset-4" style="position:fixed;">
                <div class="list-group" style="position:fixed;">

                    <form role="radio_button_form" style="position:fixed;">
                        <div class="radio">
                            <label><input type="radio" value="male" name="method">male</label>
                        </div>

                        <div class="radio">
                            <label><input type="radio" value="female" name="method">female</label>
                        </div>

                    </form>

                </div>
            </div>

        </div>
    </div>

 //this is the enter button.
<div class="row" style="padding-top: 80px; position:relative;">
    <div class="col-md-8 col-md-offset-16" style="position:relative;">
    <form id="form1" runat="server" style="position:relative;">
       <asp:LinkButton class="btn btn-info" ID="getStarted_btn" runat="server" OnClick="btn_clicked" Text="Enter" />
    </form>
    </div>
    </div>

这是我试图在我的 C# 代码中获取单选按钮值的地方:

public void btn_clicked (object sender, EventArgs args)

    {
        Console.Out.WriteLine ("sdsfdsfdfsdf");
        if (Request.Form["method"] != null)
        {
            string selectedGender = Request.Form["method"].ToString();
            Console.Out.WriteLine (selectedGender);
        }

    }

有没有人知道我做错了什么,或者有更好的方法来实现这个目标吗?

最佳答案

我已经编辑了你的代码,这是有效的。请检查

<body>
<form id="form1" runat="server" style="position: relative;">
    <div id="list_of_btns" style="padding-top: 80px; position: fixed;">
        <div class="row" style="position: absolute;">
            <div class="col-md-8 col-md-offset-4" style="position: fixed;">
                <div class="list-group" style="position: fixed;">


                    <div class="radio">
                        <label>
                            <input type="radio" value="male" name="method">male</label>
                    </div>

                    <div class="radio">
                        <label>
                            <input type="radio" value="female" name="method">female</label>
                    </div>



                </div>
            </div>

        </div>
    </div>


    <div class="row" style="padding-top: 80px; position: relative;">
        <div style="position: relative;">

            <asp:LinkButton class="btn btn-info" ID="getStarted_btn" runat="server" OnClick="btn_clicked" Text="Enter" />

        </div>
    </div>
</form>

将所有内容包含在单个表单中..

关于c# - 单选按钮值为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31108883/

相关文章:

c# - CS0436 : Type conflicts with the imported type

jquery - 如何定义具有多个 on() 事件的元素

javascript - 如果 URL 在初始页面加载时包含哈希值

javascript - 如何使用 JavaScript 将文件上传路径附加到表单?

javascript - 如何在 fullpage.js 中垂直居中图像?

javascript - Vimeo - 全屏 - 自动播放

c# - 双重/不完整的参数 Url 编码

c# - HttpUtility.HtmlEncode 不会对所有内容进行编码

c# - WPF 字符串到双转换器

javascript - 单击缩略图时图像未显示在模式中