troubleshooting Question

Setting Asp Label text and display from Javascript not working

Avatar of shelbyinfotech
shelbyinfotech asked on
Visual Basic.NETJavaScriptASP.NET
7 Comments1 Solution467 ViewsLast Modified:
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("MessageSetup({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.QuickApprovalMessage(AUTONUM, SUBDATE, PARID, ShowMessage);


        function ShowMessage(response, userContect, methodName) {
            document.getElementById('<%= lbl_QuickApprovalMessage.ClientID %>').innerText = response;
            document.getElementById('<%= div_QuickApprovalMessage.ClientID %>').style.display = "block";

<form id="Form1" method="post" runat="server" class="aspnetmaker">

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">

Server Side Function:

        <System.Web.Services.WebMethod()> _
        Public Shared Function QuickApprovalMessage(AUTONUM, SUBDATE, PARID) As String
            Dim ErrorMsg As String = ""
            QuickApprovalMessage = "No Error Message"

            Exit Function

        End Function

The Label to be displayed:

<div id="div_QuickApprovalMessage" runat="server">
    <asp:Label id="lbl_QuickApprovalMessage" forecolor="#FF0000" Font-Bold="true" runat="server" /> <%--style="display:none"--%>

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:

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros