| |

VerySource

 Forgot password?
 Register
Search
Author: yoto999

I have been engaged in .net development for a year and a half, and encountered a very difficult problem (how to cancel t

[Copy link]

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-28 18:00:01
| Show all posts
Sorry, I came home late after get off work. The test passed:
Front desk:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>Untitled page</title>
<script language="javascript">
<!--
var a = new Array();
The
function myClick(e)
{
for(var h=0;h<document.all.length;h++)
{
if(document.all(h).tagName == "INPUT"&&document.all(h).type == "radio")
{
if(document.all(h).id == e.id)
{
if(a[h] == 1)
e.checked = false;
else
e.checked = true;
}
}
}
for(var i=0;i<document.all.length;i++)
{
if(document.all(i).tagName == "INPUT"&&document.all(i).type == "radio")
{
if(document.all(i).id == e.id)
{
a[i] = 1;
}
else
{
a[i] = 0;
}
}
}

}
//-->
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem>a</asp:ListItem>
            <asp:ListItem>b</asp:ListItem>
        </asp:RadioButtonList>
</div>
    </form>
</body>
</html>


Backstage:
//...
protected void Page_Load(object sender, EventArgs e)
    {
        for(int i = 0; i <this.RadioButtonList1.Items.Count; i++)
        {
            this.RadioButtonList1.Items[i].Attributes.Add("onclick", "myClick(this);");
        }
    }
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-29 15:15:01
| Show all posts
Delete the original control, in use. NET to create
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-2 11:30:02
| Show all posts
Realized with javascript, use a hidden field to save the state of the checkbox

<script language="javascript">
function cancelCheck()
{
                                    //The specific ID can look at the generated HTML
var obj = document.getElementById("rdlist_0");

var item = document.getElementById("status");
alert(item.value);
if(item.value == 0)
{
obj.checked = true;
item.value = 1;
}
else
{
obj.checked = false;
item.value = 0;
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 416px; POSITION: absolute; TOP: 184px"
runat="server"></asp:TextBox>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 304px; POSITION: absolute; TOP: 184px" runat="server"
Width="88px">Label</asp:Label>
<asp:RadioButtonList ID="rdlist" Runat="server" style="Z-INDEX: 103; LEFT: 344px; POSITION: absolute; TOP: 264px"
Width="152px" RepeatDirection="Horizontal">
<asp:ListItem Value="1">A</asp:ListItem>
<asp:ListItem Value="2">B</asp:ListItem>
</asp:RadioButtonList>
<asp:Button id="Button1" style="Z-INDEX: 104; LEFT: 568px; POSITION: absolute; TOP: 264px" runat="server"
Width="120px" Text="Button"></asp:Button>
<input id="status" type="hidden" runat="server" value="0" style="Z-INDEX: 105; LEFT: 416px; POSITION: absolute; TOP: 392px">
</form>
</body>

Backstage

If Not IsPostBack Then
            Me.rdlist.Attributes.Add("onclick", "cancelCheck();")
        End If
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-2 14:45:01
| Show all posts
Only to find that it is messy to copy directly. . .
Organize the main content
javascript:
function cancelCheck()
{
    //The specific ID can look at the generated HTML
    var obj = document.getElementById("rdlist_0");

    var item = document.getElementById("status");
    alert(item.value);
    if(item.value == 0)
    {
         obj.checked = true;
         item.value = 1;
    }
    else
    {
         obj.checked = false;
         item.value = 0;
     }
}

html hidden domain
<input id="status" type="hidden" runat="server" value="0">

Bind events to radiobuttonlist in the background
If Not IsPostBack Then
    Me.rdlist.Attributes.Add("onclick", "cancelCheck();")
End If

Successfully achieved
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list