Reputation: 1553
I want to update label's text in an event in codebehind.
in master page label is declared like:
<asp:Content ID="WorklistBody" ContentPlaceHolderID="BodyHolder" runat="server">
<asp:Label id ="lblOutput" runat="server" class="textStyle4" ForeColor="Red"></asp:Label>
<asp:CustomValidator ID="CustomValidator1" ValidationGroup="SM" runat="server" ErrorMessage="CustomValidator" class="textStyle4" OnServerValidate="CustomValidatorServerValidate">
</asp:CustomValidator>
// tables and other items goes on here......
Developer before me used something like following to update the label;
<script language="javascript" type="text/javascript">
function ValidateComments() {
var selOption = $('#<%= ddlActions.ClientID %> option:selected').val();
if (selOption == 'C' || selOption == 'R' || selOption == 'U' || selOption == 'Q'|| selOption == 'P' || selOption == 'A') {
var comment = $('#<%= txtComments.ClientID %>').val();
comment = jQuery.trim(comment);
if (comment == '') {
if (selOption == 'C') {
$('#<%= lblOutput.ClientID %>').text('Please enter comments before processing the transaction');
}
else if (selOption == 'R') {
$('#<%= lblOutput.ClientID %>').text('Please enter comments before cancelling the transaction');
}
else if (selOption == 'U' || selOption == 'Q' || selOption == 'P' || selOption == 'A') {
$('#<%= lblOutput.ClientID %>').text('Please enter comments before assigning the transaction');
}
window.scroll(0, 0);
return false;
}
}
return true;
}
</script>
but now project expended and I gotta check a lot of logic. I want to simply update the label from codebehind.
public void BtnDoneclick(object sender, EventArgs e)
{
//logic logic logic
lblOutput.Text = @"Please enter comments before you Process this recommendation.";
}
Why this doesnt update the label? How can I update label?
I am brand new to .net environment
UPDATE:Btn Markup
<td align="right">
<div class="paddingStyle6 paddingStyle2">
<asp:Button ID="btndone" runat="server" CausesValidation="true" ValidationGroup="SM"
Text="Done" UseSubmitBehavior="True" Width="100px" OnClientClick="return ValidateComments()" OnClick="BtnDoneclick" />
</div>
</td>
Upvotes: 4
Views: 6713
Reputation: 938
If the button is in the updatepanel then only the contents of that update panel get updated. The label being modified is part of the page that gets ignored.
Try moving the button out of the update panel.
Upvotes: 6