0
I have some tags <h3>
, <p>
with display: none
or empty (usually use to display messages or some div), when clicking on some system event, these tags appear: display: block
or are filled in by innerHTML
. When I click on another event, these tags go back to what they were in the beginning: display: none
or empty.
Is there any way to prevent them from returning to their original state? That is, when you click on the event in which they appear, they stay that way until I want to deactivate them again. Because the second event you click on, it could be the case that those tags should be activated, you know? Soon I wouldn’t need to call a method that activates them again. When I need to disable them, just pass the display: none
(as it was in the beginning). I could understand?
So, what happens is that every time I trigger an event there is a postBack, right? And these tags (div, H3) go back to their initial values. It’s not something I told you to do, I didn’t want you to go back to your initial values.
I simply create a <div>, this has some data to be presented, I leave it as display: None. When I need to show it, I switch to display: block. But when clicking on another event (from a button or a selectedIndexChanged) they return to the initial value of "None", I believe it is because the events make a postBack. So that’s right: every time a postBack happens the tags go back to the initial state?
– HeyJoe
Yes, every postbabk HTML is recreated. It’s not even the same tag, it’s a completely new.
– Thiago Lunardi
I found it really boring, man. So there’s nothing to do? I have to call the functions again to pass to the display: block everything again?
– HeyJoe
In vdd there are several things one can do. By being using MVC with Razor, I recommend create an Html Helper that will return this
<div>
being displayed or not. Another way is to setdisplay:none/block;
usingViewBag
guided by the previous postback. Lastly, and what I recommend not to do, is to put a@if
in View and there set thedisplay
of<div>
.– Thiago Lunardi
I’m not using MVC, if this solves that kind of problem, then I’ll study it.
– HeyJoe
Are you doing with Webforms? Like, with Updatepanel?
– Thiago Lunardi
With Webforms, I call JS functions with a Page.ClientScript.Registerclientscriptblock().
– HeyJoe
Yes, using this you have to recover all the HTML states. And run away from Webforms as soon as possible.
– Thiago Lunardi
Thanks, yeah, I thought it was to recover all the states of the tags a bag, man, I’ll study the MVC. Thanks!
– HeyJoe
Do you have any book/ booklet to recommend me?
– HeyJoe
Official ASP.NET Channel - https://www.asp.net/learn
– Thiago Lunardi