Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiview - View Clear State
    text
    copied!<p>Thanks in advance for your help.</p> <p>I am using c#.net.</p> <p>I have two views on my webpage (contained within one multiview), both contain buttons. </p> <p>view_1 </p> <p>Contains a repeater/datasource and an custom made ‘edit’ button (which holds the ID for each row returned).</p> <p>view_2</p> <p>Contain an ‘update’ form and a ‘update’ button. When the user presses the update button the information within the database for that particular row is updated.</p> <p>The problem I believe lies with my ‘update’ button within view_2 </p> <p>Code behind (‘update’ button), I have an if statement:</p> <pre><code> protected void Page_Load(object sender, EventArgs e) { updateSuccessFailed.Visible = false; if (!Page.IsPostBack) { _multiView1.ActiveViewIndex = 0; } } protected void update_Click(object sender, EventArgs e) </code></pre> <p>{</p> <pre><code> var Id = Convert.ToInt32((ID.Value)); notYetUpdated.Visible = true; updateSuccessFailed.Visible = false; tblV updateV = new tblV(); updateV.vID = venueId; updateV.vame = updateName.ToString(); updateV.vPostcode = updatePropPostcode.ToString(); if (vRepos.Update(updateV)) { notYetUpdated.Visible = false; updateSuccessFailed.Visible = true; updateMessage.Text = "Updated."; } else { notYetUpdated.Visible = false; updateSuccessFailed.Visible = true; updateMessage.Text = "An error has occurred, please try again."; } } </code></pre> <p>_view2</p> <pre><code>&lt;asp:View ID="_view2" runat="server"&gt; &lt;div style="text-align:center" runat="server" id="notYetUpdated"&gt; &lt;table border="0" cellspacing="1"&gt; &lt;tr&gt; &lt;td style="text-align:left;"&gt;Name&lt;/td&gt; &lt;td style="text-align:left;"&gt;&lt;asp:TextBox ID="updateName" MaxLength="60" runat="server" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="text-align:left;"&gt;Postcode&lt;/td&gt; &lt;td style="text-align:left;"&gt;&lt;asp:TextBox ID="updatePropPostcode" MaxLength="60" runat="server" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;&lt;br /&gt; &lt;asp:Button ID="updateVCancel" Text="Cancel" runat="server" onclick="cancel_Click" CssClass="standardButton" /&gt; &lt;asp:Button ID="updateVConfirm" Text="Update" runat="server" onclick="update_Click" CssClass="standardButton" /&gt; &lt;asp:HiddenField ID="vUpdateID" runat="server" /&gt; &lt;/div&gt; &lt;div style="text-align:center" runat="server" id="updateSuccessFailed"&gt; &lt;p&gt;&lt;asp:Label ID="updateMessage" runat="server" /&gt;&lt;/p&gt; &lt;asp:Button ID="updateBack" Text="Back To Start" runat="server" onclick="backToStart_Click" CssClass="standardButton" /&gt; &lt;/div&gt; &lt;/asp:View&gt; </code></pre> <p>notYetUpdated / updateSuccessFailed are div’s which hold different information. </p> <p>When the user first ‘updates’ a record it make the right div visible. (notYetUpdated – holds the form information / updateSuccessFailed – holds a message to state whether the record has been updated or not). However when you access the view_2 again it accesses the update_Click event and updateSuccessFailed is visible even though it shouldn’t be.</p> <p>I thought I could clear all stored information within the viewstates with the code below, however this is not working.</p> <pre><code> ViewState.Clear(); ClearChildViewState(); </code></pre> <p>Thanks </p> <p>Clare :-)</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