Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript Changes clear after postback
    text
    copied!<p>Here I am posting code,</p> <p>ASP:</p> <pre><code> &lt;%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&gt; &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"&gt; &lt;script type="text/javascript"&gt; function ShowHideBox() { boxdl.style.display = 'none'; } &lt;/script&gt; &lt;/asp:Content&gt; &lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt; First Value:&lt;asp:TextBox ID="first" runat="server" &gt;&lt;/asp:TextBox&gt;&lt;br /&gt; Second Value:&lt;asp:TextBox ID="second" runat="server" &gt;&lt;/asp:TextBox&gt;&lt;br /&gt; Calculation:&lt;asp:TextBox ID="calc" runat="server" &gt;&lt;/asp:TextBox&gt;&lt;br /&gt; &lt;asp:Button ID="Calculate" runat="server" Text="Calculate" onclick="Calculate_Click" /&gt; &lt;div onclick="ShowHideBox();" style="display:block;height:10px;width:100px;background-color:#258000;"&gt;&lt;/div&gt; &lt;div style="background-color:#852000;width:100px;height:100px;display:block;border:black 1px solid;" id="boxdl"&gt; &lt;/div&gt; &lt;/asp:Content&gt; </code></pre> <p>C# Code:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Calculate_Click(object sender, EventArgs e) { calc.Text = (int.Parse(first.Text) + int.Parse(second.Text)).ToString(); } } </code></pre> <p>when I click on green box, redbox disappears, but when I click on calculate button, it calculate result of two text boxes and shows result in third textbox, but the problem is that the redbox appears after occurrence of postback event, why??? is there any solution to prevent this problem??? this is just a demo. this thing is used lots of times in my project...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload