Hello all,
Thanks in advance for your help.
I am using c#.net.
I have two views on my webpage (contained within one multiview), both contain buttons.
view_1
Contains a repeater/datasource and an custom made ‘edit’ button (which holds the ID for each row returned).
view_2
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.
The problem I believe lies with my ‘update’ button within view_2
Code behind (‘update’ button), I have an if statement:
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)
{
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.";
}
}
_view2
<asp:View ID="_view2" runat="server">
<div style="text-align:center" runat="server" id="notYetUpdated">
<table border="0" cellspacing="1">
<tr>
<td style="text-align:left;">Name</td>
<td style="text-align:left;"><asp:TextBox ID="updateName" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td style="text-align:left;">Postcode</td>
<td style="text-align:left;"><asp:TextBox ID="updatePropPostcode" MaxLength="60" runat="server" /></td>
</tr>
</table><br />
<asp:Button ID="updateVCancel" Text="Cancel" runat="server" onclick="cancel_Click" CssClass="standardButton" />
<asp:Button ID="updateVConfirm" Text="Update" runat="server" onclick="update_Click" CssClass="standardButton" />
<asp:HiddenField ID="vUpdateID" runat="server" />
</div>
<div style="text-align:center" runat="server" id="updateSuccessFailed">
<p><asp:Label ID="updateMessage" runat="server" /></p>
<asp:Button ID="updateBack" Text="Back To Start" runat="server" onclick="backToStart_Click" CssClass="standardButton" />
</div>
</asp:View>
notYetUpdated / updateSuccessFailed are div’s which hold different information.
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.
I thought I could clear all stored information within the viewstates with the code below, however this is not working.
ViewState.Clear();
ClearChildViewState();
Thanks
Clare :-)