shelbyinfotech
asked on
Setting Asp Label text and display from Javascript not working
Step 1 - Fire off a javascript function to pass parameters to Server Side Function
Step 2 - Return text to javascript function to be displayed in a label on the page.
>>>>>>
I have a LinkButton on a datagrid that fires off a JavaScript Function and passes parameters to it:
<asp:LinkButton id="lnkApprove" Width="120" runat="server" Text="Quick Approval" OnClientClick= '<%# String.Format("MessageSetu p({0}, ""{1}"", ""{2}"");", Eval("AUTONUM"), Eval("SUBDATE"), Eval("PARID")) %>' />
>>>>>
The javascript function "MessageSetup" then passes these parameters to Server Side Function.
<script type="text/javascript">
function MessageSetup(AUTONUM, SUBDATE, PARID) {
PageMethods.QuickApprovalM essage(AUT ONUM, SUBDATE, PARID, ShowMessage);
}
function ShowMessage(response, userContect, methodName) {
document.getElementById('< %= lbl_QuickApprovalMessage.C lientID %>').innerText = response;
document.getElementById('< %= div_QuickApprovalMessage.C lientID %>').style.display = "block";
}
<form id="Form1" method="post" runat="server" class="aspnetmaker">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
.
.
.
Server Side Function:
<System.Web.Services.WebMe thod()> _
Public Shared Function QuickApprovalMessage(AUTON UM, SUBDATE, PARID) As String
Dim ErrorMsg As String = ""
QuickApprovalMessage = "No Error Message"
Exit Function
End Function
The Label to be displayed:
<div id="div_QuickApprovalMessa ge" runat="server">
<asp:Label id="lbl_QuickApprovalMessa ge" forecolor="#FF0000" Font-Bold="true" runat="server" /> <%--style="display:none"-- %>
</div>
In function ShowMessage, I've verified "response" is being generated and JavaScript function can read it. It's just that the Label won't display anything.
I'm using this link as my template: https://www.aspsnippets.com/Articles/Calling-server-side-function-from-JavaScript-in-ASP.Net.aspx
Step 2 - Return text to javascript function to be displayed in a label on the page.
>>>>>>
I have a LinkButton on a datagrid that fires off a JavaScript Function and passes parameters to it:
<asp:LinkButton id="lnkApprove" Width="120" runat="server" Text="Quick Approval" OnClientClick= '<%# String.Format("MessageSetu
>>>>>
The javascript function "MessageSetup" then passes these parameters to Server Side Function.
<script type="text/javascript">
function MessageSetup(AUTONUM, SUBDATE, PARID) {
PageMethods.QuickApprovalM
}
function ShowMessage(response, userContect, methodName) {
document.getElementById('<
document.getElementById('<
}
<form id="Form1" method="post" runat="server" class="aspnetmaker">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
.
.
.
Server Side Function:
<System.Web.Services.WebMe
Public Shared Function QuickApprovalMessage(AUTON
Dim ErrorMsg As String = ""
QuickApprovalMessage = "No Error Message"
Exit Function
End Function
The Label to be displayed:
<div id="div_QuickApprovalMessa
<asp:Label id="lbl_QuickApprovalMessa
</div>
In function ShowMessage, I've verified "response" is being generated and JavaScript function can read it. It's just that the Label won't display anything.
I'm using this link as my template: https://www.aspsnippets.com/Articles/Calling-server-side-function-from-JavaScript-in-ASP.Net.aspx
ASKER
"QuickApprovalMessage" is the Function name - which is defined as a string.
"lbl_QuickApprovalMessage" is the label name.
"lbl_QuickApprovalMessage"
ASKER
I've stepped through the code and while stepping through the post-back in code behind, the message appears as it is supposed to. Then Visual Studio steps through the javascript code (like it's compiling it?) and the message disappears.
You'll want to use console.log() to "step" through the JS code.
ASKER
I've attached screen prints to help explain what I am seeing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Contributors did not provide assistance...
Open in new window
refer the the Text property of the label?
Open in new window