Avatar billede eromaster Nybegynder
06. november 2011 - 11:21 Der er 1 løsning

ASP:UpdatePanel + Triggers virker ikke

Jeg har følgende kode:
<strong>Publish to my network(s):</strong><br />
        <asp:RadioButton ID="CreateSwapNetworkCustom" runat="server" ValidationGroup="ValidationGRPCreateSwap"
            GroupName="CreateSwapNetworkRadio" Text="Custom" OnCheckedChanged="CreateSwapNetworkCustom_CheckedChanged"
            AutoPostBack="true" />
        <asp:RadioButton ID="CreateSwapNetworkAll" runat="server" ValidationGroup="ValidationGRPCreateSwap"
            GroupName="CreateSwapNetworkRadio" Text="All" Checked="true" OnCheckedChanged="CreateSwapNetworkAll_CheckedChanged"
            AutoPostBack="true" />
        <asp:UpdatePanel ID="d" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="CreateSwapNetworkCustom" EventName="CheckedChanged" />
                <asp:AsyncPostBackTrigger ControlID="CreateSwapNetworkAll" EventName="CheckedChanged" />
            </Triggers>
            <ContentTemplate>
                <asp:CheckBoxList ID="CreateSwapNetworkList" runat="server" Visible="false" ValidationGroup="ValidationGRPCreateSwap" />
            </ContentTemplate>
        </asp:UpdatePanel>

Code behind:
//Create swap - Custom network or All network
    protected void CreateSwapNetworkCustom_CheckedChanged(object sender, EventArgs e)
    {
        if (CreateSwapNetworkCustom.Checked == true)
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("SELECT * FROM NetworkUserTBL WHERE UserID ='" + Session["UserID"] + "' AND Authed ='" + "1" + "'", con);
            SqlDataReader PrintUserNetworks = cmd.ExecuteReader();

            while (PrintUserNetworks.Read())
            {
                con2.Open();
                SqlCommand cmd2 = new SqlCommand("SELECT * FROM NetworkTBL WHERE ID ='" + PrintUserNetworks["NetworkID"] + "'", con2);
                SqlDataReader PrintNetworkInfo = cmd2.ExecuteReader();
                PrintNetworkInfo.Read();

                CreateSwapNetworkList.Items.Add(new ListItem(PrintNetworkInfo["Name"].ToString(), PrintNetworkInfo["ID"].ToString()));

                PrintNetworkInfo.Dispose();
                con2.Close();
            }

            PrintUserNetworks.Dispose();
            con.Close();

            CreateSwapNetworkList.Visible = true;
        }
        if (CreateSwapNetworkCustom.Checked == false)
        {
            CreateSwapNetworkList.Visible = false;
        }
    }
    protected void CreateSwapNetworkAll_CheckedChanged(object sender, EventArgs e)
    {
        if (CreateSwapNetworkAll.Checked == true)
        {
            CreateSwapNetworkList.Visible = false;
        }
        if (CreateSwapNetworkAll.Checked == false)
        {
            CreateSwapNetworkList.Visible = true;
        }
    }


Mit problem er at de 2 radio buttons kun virker den ene vej. Dvs. at hvis jeg trykker på Custom, så kommer min checkdownlist, men hvis jeg klikker tilbage på All, så sker der intet.
Avatar billede eromaster Nybegynder
06. november 2011 - 12:13 #1
<asp:UpdatePanel ID="CreateSwapNetworkUpdatePanel" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:RadioButton ID="CreateSwapNetworkCustom" runat="server" ValidationGroup="ValidationGRPCreateSwap"
                    GroupName="CreateSwapNetworkRadio" Text="Custom" OnCheckedChanged="CreateSwapNetworkCustom_CheckedChanged"
                    AutoPostBack="true" />
                <asp:RadioButton ID="CreateSwapNetworkAll" runat="server" ValidationGroup="ValidationGRPCreateSwap"
                    GroupName="CreateSwapNetworkRadio" Text="All" Checked="true" OnCheckedChanged="CreateSwapNetworkAll_CheckedChanged"
                    AutoPostBack="true" />
                <asp:CheckBoxList ID="CreateSwapNetworkList" runat="server" AutoPostBack="false" Visible="false" ValidationGroup="ValidationGRPCreateSwap" />
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="CreateSwapNetworkCustom" EventName="CheckedChanged" />
                <asp:AsyncPostBackTrigger ControlID="CreateSwapNetworkAll" EventName="CheckedChanged" />
            </Triggers>
        </asp:UpdatePanel>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester