Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net Javascript error on check change

Hi

I am getting a Compilation Error in the following code in my ASP.net wen form. The JavaScript shown further down runs fine in the button click shown
in the second piece of code

  <asp:RadioButton ID="RadioButtonSimple" OnCheckedChanged="showLoading();"  runat="server" AutoPostBack="True" Checked="True" 

Open in new window


                              <asp:Button ID="btnClear" runat="server" BackColor="White" CssClass="roundedCornerBigButton" ForeColor="#000066" Text="Clear" Width="200px" OnClientClick="showLoading();" />

Open in new window


   	<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
	<script type="text/javascript">
		//<![CDATA[
	    function showLoading() {
	        $('.pleaseWait').show();
	    }
		//]]>
       </script>

Open in new window

Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

What is the error?
Hi,

You will have to call server side function with OnCheckedChanged event and through that you can specify your JS function. Check below for your reference-

<asp:CheckBox OnCheckedChanged="checkchanged" runat="server" AutoPostBack="true" />

       protected void checkchanged(object sender, EventArgs e)
       {
           this.ClientScript.RegisterStartupScript(this.GetType(), "registerscript", "alert('hi');", true);
       }

Open in new window

Avatar of Murray Brown

ASKER

Hi Julian the error I get is as follows

Server Error in '/' Application.

Compilation Error 
  Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

 Compiler Error Message: BC30037: Character is not valid.

Source Error:

Line 482:   <td></td>
Line 483:   <td>
Line 484:   <asp:RadioButton ID="RadioButtonSimple" OnCheckedChanged="showLoading();"   runat="server" AutoPostBack="True" Checked="True" ForeColor="#000066" GroupName="Radio1" Text="Simple View" />
Line 485:   </td>
Line 486:   <td></td>

Open in new window

Thanks Rikin. I don't fully understand where to put that
Hi. I thought I had got things to work with a VB.net version of Rikin's answer but with more testing I found that the following code didn't function properly.
The "Please Wait" message popped up after my other code ran

  Protected Sub RadioButtonDetailed_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButtonDetailed.CheckedChanged

        Me.ClientScript.RegisterStartupScript(Me.GetType(), "registerscript", "showLoading();", True)
        Call oSearch()
    End Sub

Open in new window

As @Rikin stated, those On* events are server-side, not client-side. Therefore, the only  Javascript they will immediately fire when your user interacts with the control is the postback function, which in turn calls the server-side event you're looking for.

I believe the error is being caused by the semicolon in showLoading(); because VB.NET generally doesn't use those.

You're already using jQuery in your HTML, so I suggest using that to handle the client-side change event. It will look something like the following:

$('.roundedCornerBigButton').click(function() {
    $('.pleaseWait').show();
});

Open in new window

Hi,

What is "Call oSearch()" ?

And what error are you facing ?
Thanks Kelvin. Unfortunately removing the semi-colon didn't help
Hi Rikin. oSearch is some basic code that doesn't interfere with this. Using what you gave me the "Please Wait" box does pop up but not straight away. It only pops up at the end when my other code has run
ASKER CERTIFIED SOLUTION
Avatar of Kelvin McDaniel
Kelvin McDaniel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial