Murray Brown
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
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"
<asp:Button ID="btnClear" runat="server" BackColor="White" CssClass="roundedCornerBigButton" ForeColor="#000066" Text="Clear" Width="200px" OnClientClick="showLoading();" />
<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>
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-
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);
}
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>
ASKER
Thanks Rikin. I don't fully understand where to put that
ASKER
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
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
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:
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();
});
Hi,
What is "Call oSearch()" ?
And what error are you facing ?
What is "Call oSearch()" ?
And what error are you facing ?
ASKER
Thanks Kelvin. Unfortunately removing the semi-colon didn't help
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.