I have a simple task - to change the link to the link to change the state of the checkbox, but I am new to ASP.NET and have some problems.
I can do the same with HtmlControl and JavaScript:
<script type="text/javascript" language="javascript"> function checkbox_onChanged(checked) { if (checked) { document.location = '?type=request_in&show=all'; } else { document.location = '?type=request_in&show=unapproved'; } } function checkbox_onLoad(checkbox) { checkbox.checked = true; } </script> <form action="" method="get"> <input type="checkbox" name="checkbox" onload="checkbox_onLoad(this)" onchange="checkbox_onChanged(this.checked)" />Show all </form>
but I want to hide it from users. So I:
<asp:CheckBox runat="server" ID="check" OnCheckedChanged="check_CheckedChanged" AutoPostBack="True" Text="Show all" /> protected void check_CheckedChanged(object sender, EventArgs e) { Response.Redirect(String.Format("{0}?type=request_in&show={1}", Request.Path, checkViewRequestIn.Checked ? "all" : "unapproved")); } protected void Page_Load(object sender, EventArgs e) { var show = Request["show"]; if (!String.IsNullOrEmpty(show) && String.Equals(show, "all")) { checkViewRequestIn.Checked = true; } }
But it seems that a change in the check state at boot again triggers an event, and the check box is always checked!
Another question - is there another way to redirect to one page without specifying a file name? I mean, for example, in JavaScript - are only variables needed?
source share