views:

2136

answers:

2

When i clicked a button control on asp.net page, my radiobuttonlist is returning back unchecked after postback.

<asp:RadioButtonList ID="rblSgkOzel" runat="server" EnableViewState="true">
    <asp:ListItem Text="SGK Kapsamında" Value="sgk" Selected="True"/>
    <asp:ListItem Text="Özel" Value="ozel" />
    <asp:ListItem Text="Hasta Adına" Value="hasta" />
</asp:RadioButtonList>


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="denemeRepeater.aspx.cs"
    Inherits="KlinikMuhasebe.denemeRepeater" %>

<%@ Import Namespace="MedulaRADClassLib" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
    <link href="JS/reset-fonts-grids.css" rel="stylesheet" type="text/css" />
    <link href="css.css" rel="stylesheet" type="text/css" />
    <link href="_cssV3.css" rel="stylesheet" type="text/css" />

    <script src="JS/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="JS/liquid-canvas.js" type="text/javascript"></script>

    <script src="JS/liquid-canvas-plugins.js" type="text/javascript"></script>

    <script type="text/javascript" src="js_Eski/JScript.js" language="javascript"></script>

    <script type="text/javascript" src="js_Eski/overlib.js" language="javascript"></script>

    <script src="JS/boxy/jquery.boxy.js" type="text/javascript"></script>

    <style>
        .imgOpenClose
        {
        }
        body
        {
            color: Black;
        }
    </style>

    <script type="text/javascript">
        $(document).ready(function() {

            $('.imgOpenCloseKurum').click(function() {
                if ($(this).attr("src") == "images/openTree.gif") {
                    $(this).attr("src", "images/closeTree.gif");
                    $($(this).parent().get(0)).find('div').eq(0).show();
                }
                else {
                    $(this).attr("src", "images/openTree.gif");
                    $($(this).parent().get(0)).find('div').eq(0).hide();
                }
            });

            $('.imgOpenClose').click(function() {
                if ($(this).attr("src") == "images/openTree.gif") {
                    $(this).attr("src", "images/closeTree.gif");
                    $(this).parent().find('div').eq(0).show();
                }
                else {
                    $(this).attr("src", "images/openTree.gif");
                    $(this).parent().find('div').eq(0).hide();
                }
            });


            $("input:radio").click(function() {
                $("input:radio").each(function() {
                    $(this).attr("checked", "")
                });
                $(this).attr("checked", "checked");
            }).attr("checked", "");

            $("input:checkbox").click(function() {
                if ($(this).attr('checked')) {
                    $(this).next().html("Ücretli Seans");
                    //$(this).attr('checked', '');
                }
                else {
                    $(this).next().html("Bedelsiz Seans");
                    //$(this).attr('checked', 'checked');
                }

            })
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="text-align: left;">
        <div class="divKriter">
            <table>
                <thead>
                    <tr>
                        <th colspan="2">
                            FATURA BASKI KRİTERLERİ
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            <asp:RadioButtonList ID="rblSgkOzel" runat="server" EnableViewState="true">
                                <asp:ListItem Text="SGK Kapsamında" Value="sgk" Selected="True"/>
                                <asp:ListItem Text="Özel" Value="ozel" />
                                <asp:ListItem Text="Hasta Adına" Value="hasta" />
                            </asp:RadioButtonList>
                        </td>
                        <td>
                            <asp:TextBox ID="txtTarihi" runat="server" ToolTip="Son Tarihi" />
                            <cc1:CalendarExtender ID="txtTarihi_CalendarExtender" runat="server" Enabled="True"
                                TargetControlID="txtTarihi" Format="dd.MM.yyyy">
                            </cc1:CalendarExtender>
                            &nbsp;<br />
                            <asp:CheckBox ID="cbBedelsiz" runat="server" Text="Ücretli Seans" Checked="true" />
                            <br />
                            <asp:Button ID="btnFaturaNolariGetir" runat="server" Text="Faturaları Getir" OnClick="btnFaturaNolariGetir_Click" />
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            <asp:DropDownList ID="ddlFaturaNolar" runat="server" />
                            <asp:Button ID="btnFaturaDetaylariniGetir" runat="server" Text="Fatura Detayları"
                                OnClick="btnFaturaDetaylariniGetir_OnClick" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <br />
        <br />
        <br />
        <br />
        <asp:Repeater ID="rptSGK" runat="server" OnItemDataBound="rpt_OnItemDataBound">
            <ItemTemplate>
                <div class="divKurumItem">
                    <img class="imgOpenCloseKurum" src="images/openTree.gif" />
                    <asp:RadioButton ID="rbKurum" runat="server" GroupName="rbKurumlar" />
                    <%# DataBinder.Eval(Container.DataItem, "kurumAdi")%>
                    <div style="display: none; margin-left: 10px;">
                        <asp:Repeater ID="rptHastalar" runat="server" OnItemDataBound="rptHastalar_OnItemDataBound">
                            <ItemTemplate>
                                <div style="display: block; margin-left: 10px;">
                                    <img class="imgOpenClose" src="images/openTree.gif" />
                                    <%# DataBinder.Eval(Container.DataItem, "adiSoyadi")%><br />
                                    <div id='hid_<%# DataBinder.Eval(Container.DataItem, "refHasta_id")%>' style="margin: 10px;
                                        display: none;">
                                        <asp:HiddenField runat="server" ID="hdn1" Value='<%# total = 0 %>' />
                                        <asp:Repeater ID="rptSeanslar" runat="server">
                                            <HeaderTemplate>
                                                <table border="1" cellpadding="5" cellspacing="2" style="margin-left: 30px;">
                                                    <thead>
                                                        <tr>
                                                            <th>
                                                                Seans Tarihi
                                                            </th>
                                                            <th>
                                                                Başvuru No.
                                                            </th>
                                                            <th>
                                                                Fatura Teslim No.
                                                            </th>
                                                            <th>
                                                                Fatura No.
                                                            </th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <tr>
                                                    <td>
                                                        <%# DataBinder.Eval(Container.DataItem, "tarihi", "{0:d}") %>
                                                    </td>
                                                    <td>
                                                        <%# (rblSgkOzel.SelectedIndex==0) ? DataBinder.Eval(Container.DataItem, "basvuruNo") : "" %>
                                                    </td>
                                                    <td>
                                                        <%# (rblSgkOzel.SelectedIndex==0) ? DataBinder.Eval(Container.DataItem, "faturaTeslimNo") : "" %>
                                                    </td>
                                                    <td>
                                                        <%# (rblSgkOzel.SelectedIndex==0) ? DataBinder.Eval(Container.DataItem, "faturaNo") : ""%>
                                                    </td>
                                                </tr>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                </tbody> </table> </div>
                                            </FooterTemplate>
                                        </asp:Repeater>
                                    </div>
                                    <asp:HiddenField runat="server" ID="hdn" Value='<%# total = total + 1 %>' />
                            </ItemTemplate>
                            <FooterTemplate>
                                <div style="width: 500px; text-align: right; display: block;">
                                    Toplam Satır Sayısı:
                                    <%# total %>
                                </div>
                            </FooterTemplate>
                        </asp:Repeater>
                    </div>
                    <br />
                </div>
            </ItemTemplate>
        </asp:Repeater>
        <br />
        <br />
        <asp:Repeater ID="rptOzel" runat="server" OnItemDataBound="rpt_OnItemDataBound">
            <ItemTemplate>
                <div class="divKurumItem">
                    <img class="imgOpenCloseKurum" src="images/openTree.gif" />
                    <asp:RadioButton ID="rbKurumOzel" runat="server" GroupName="rbKurumlar" />
                    <%# DataBinder.Eval(Container.DataItem, "kurumAdi")%>
                    <div style="display: none; margin-left: 10px;">
                        <asp:Repeater ID="rptHastalar" runat="server" OnItemDataBound="rptHastalar_OnItemDataBound">
                            <ItemTemplate>
                                <div style="display: block; margin-left: 10px;">
                                    <img class="imgOpenClose" src="images/openTree.gif" />
                                    <%# DataBinder.Eval(Container.DataItem, "adiSoyadi")%><br />
                                    <div id='hid_<%# DataBinder.Eval(Container.DataItem, "refHasta_id")%>' style="margin: 10px;
                                        display: none;">
                                        <asp:HiddenField runat="server" ID="hdn1" Value='<%# total = 0 %>' />
                                        <asp:Repeater ID="rptSeanslarOzel" runat="server">
                                            <HeaderTemplate>
                                                <table border="1" cellpadding="5" cellspacing="2" style="margin-left: 30px;">
                                                    <thead>
                                                        <tr>
                                                            <th>
                                                                Seans Tarihi
                                                            </th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <tr>
                                                    <td>
                                                        <asp:CheckBox ID="cbSeansOzel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "tarihi", "{0:d}") %>' />
                                                    </td>
                                                </tr>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                </tbody> </table> </div>
                                            </FooterTemplate>
                                        </asp:Repeater>
                                    </div>
                                    <asp:HiddenField runat="server" ID="hdn" Value='<%# total = total + 1 %>' />
                            </ItemTemplate>
                            <FooterTemplate>
                                <div style="width: 500px; text-align: right; display: block;">
                                    Toplam Satır Sayısı:
                                    <%# total %>
                                </div>
                            </FooterTemplate>
                        </asp:Repeater>
                    </div>
                    <br />
                </div>
            </ItemTemplate>
        </asp:Repeater>
    </div>
    </form>
</body>
</html>
+1  A: 

UPDATE: After you posted the updated code, I can tell that the problem is in your jQuery code. It is set to uncheck all the radio buttons as soon as the page loads.

You need to change this:

$("input:radio").click(function() {
     $("input:radio").each(function() {
         $(this).attr("checked", "")  //uncheck all radio buttons in page
     });
     $(this).attr("checked", "checked"); //check only the selected radio
  }).attr("checked", ""); //Unchecks all radio buttons when page loads

To This:

$("input:radio").click(function() {
     $("input:radio").each(function() {
         $(this).attr("checked", "")
     });
    $(this).attr("checked", "checked");
});

I added comments to explain what your jQuery code is doing.

Jose Basilio
yes, absoultly yes.. while i send the aspx code, i didn't have any hope :)
uzay95
+1  A: 

Are you binding the list in the Page_Load method?

If so, make sure you are binding only when the page is not posted back, like such:

protected void Page_Load(object sender, EventArgs) 
{
    if (!IsPostBack) 
    {
        //Bind to the list in this block
    }
}
Andreas Grech