Tag with display: None - Asp net

Asked

Viewed 103 times

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.

1 answer

2


There are two golden rules in the programming world:

  1. Computer does not think: it does not analyze and makes no decision other than what it was instructed to do;
  2. Computer is not wrong: it does exactly what it was instructed to do, exactly;

This applies in your scenario, if an object is having its state changed, it is because there is something that is changing it. Fact.

One must then find out what action is doing this, and condition not to do more.

Trying to stop the state from changing, without identifying who’s doing it and why, it’s like a car with a leaked fuel tank, but instead of fixing the hole, it’s simply attaching another tank to it so the fuel doesn’t run out so fast.

Find out why your object is having its state restored, so it will solve the problem definitely, and with lower processing cost possible.

  • 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?

  • Yes, every postbabk HTML is recreated. It’s not even the same tag, it’s a completely new.

  • 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?

  • 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 set display:none/block; using ViewBag guided by the previous postback. Lastly, and what I recommend not to do, is to put a @if in View and there set the display of <div>.

  • I’m not using MVC, if this solves that kind of problem, then I’ll study it.

  • Are you doing with Webforms? Like, with Updatepanel?

  • With Webforms, I call JS functions with a Page.ClientScript.Registerclientscriptblock().

  • Yes, using this you have to recover all the HTML states. And run away from Webforms as soon as possible.

  • Thanks, yeah, I thought it was to recover all the states of the tags a bag, man, I’ll study the MVC. Thanks!

  • Do you have any book/ booklet to recommend me?

  • Official ASP.NET Channel - https://www.asp.net/learn

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.