Keep if click on backlink

I have a checkbox set as false by default in aspx. Then there is a function that determines whether it is true or false, the problem is that there is a text field on the page, and there is a TextChange event on this text field, when I enter text into the text field, and then go to the checkbox, which at this time is displayed for the first time when I click on the pop-up messages of the entire page and clear the check box to clear the check box. Then I need to click it again and then it gets stuck .. what can I do to get it to insert the first click?

Can I use some javascript for this or what do you think are my options?

protected void myTextbox_TextChanged(object sender, EventArgs e) { ShowCheckBox(true); } private void ShowCheckBox(bool ckVal) { myCheckBox.Visible = ckVal; } 
+6
source share
5 answers

why not add a text box inside the update panel something like this:

 <asp:UpdatePanel runat="server" ID="test"> <ContentTemplate> <asp:TextBox ID="TEXTBOX" runat="server" Visible="true" AutoPostBack="true" OnTextChanged="checkUser" >Page Name</asp:TextBox> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="TEXTBOX" EventName="TextChanged" /> </Triggers> </asp:UpdatePanel> 
+6
source

My best guess is that the initialization of your checkbox (what sets Checked to false) is performed on every postback. For instance. change it

 protected void Page_Load(object sender, EventArgs e) { myCheckBox.Checked = false; } 

to that

 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) myCheckBox.Checked = false; } 

However, we will need to see another code before we can help you. Part of the problem may be that the ViewState is not saved when the control is not visible. If all you want to do is show / hide it, use javascript as others suggested.

Here is an example with jQuery:

 $(document).ready(function (){ $("#myTextBox").change(function() { $("#myCheckBox").show(); }); }); 
+5
source

If I were you, I would write some code on the client side to show this flag or hide it, writing code to suck on the server side is not good and requires additional roundtrip also you can use the update panel for this

+4
source

Check box if .Visible = false not displayed to the client. Therefore, when postback occurs, the default value of "false" is what it is set to.

You can visualize control all the time and switch visibility through CSS, so the checkbox is always part of the control tree and its ViewState is saved.

style="display:none" and style="display:inline"

+3
source

You have not published all the code, so I’ll just guess. Try setting the AutoPostBack property of the text field to false and see if it fixes this.

If this is not the case, submit your code or a complete sample code that reproduces the problem.

0
source

Source: https://habr.com/ru/post/899469/


All Articles