I have used the following code. This code works sometime but sometime not works. Please explain the resion and modify the code.
.aspx page:
<td valign="top" align="left" width="10px" runat="server" id="tdNoteRightBar">
<asp:HiddenField runat="server" ID="hidNoteId" Value='<%# Eval("PK_ID").ToString() %>' />
<asp:ImageButton ID="ibtnAddToPin" runat="server" ImageUrl="~/Images/pin_addto.png"
OnClick="ibtnAddToPin_Click" ToolTip="Pin this note to stay on top." Style="padding-right: 1px;" />
<asp:ImageButton ID="ibtnPinMarkedRemovePin" runat="server" ImageUrl="~/Images/pin_marked.png"
Visible="false" OnClick="ibtnPinMarkedRemovePin_Click" Style="padding-top: 2px;" />
</td>
.cs page
protected void ibtnAddToPin_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
try
{
ListViewDataItem dataItem = (ListViewDataItem)(((ImageButton)sender).Parent.Parent);
int noteId = Convert.ToInt32(((HiddenField)dataItem.FindControl("hidNoteId")).Value);
Notes.PinANote(noteId);
}
catch (Exception ex)
{
ExceptionLogger.LogException(ex);
lblError.ForeColor = System.Drawing.Color.Red;
lblError.Text = "Error occurred while pinning the note.";
}
}
protected void ibtnPinMarkedRemovePin_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
try
{
ListViewDataItem dataItem = (ListViewDataItem)(((ImageButton)sender).Parent.Parent);
int noteId = Convert.ToInt32(((HiddenField)dataItem.FindControl("hidNoteId")).Value);
Notes.UnPinANote(noteId);
}
catch (Exception ex)
{
ExceptionLogger.LogException(ex);
lblError.ForeColor = System.Drawing.Color.Red;
lblError.Text = "Error occurred while un pinning the note.";
}
}
@Shalini Pls check whether you provides any validation controls?.I think some times when it works that condition satisfies and not works when validation fails.So pls check the controls.Add property
Validation Group="abc"to the controls which requries some validation.and try again.