Click here to Skip to main content
15,667,014 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more:
When I set a onClientClick=”jsfunction()” on a submit button, the validationsummary message box would not show up;
How can I trigger validationsummary message box in the function jsfunction(), if it is invalid page?
Updated 29-Apr-11 6:37am
Monjurul Habib 29-Apr-11 13:57pm    
please clarify your question.
Sid.Mup 29-Apr-11 14:25pm    
Here is the detail description of my problem...
Sid.Mup 29-Apr-11 14:26pm    
I am using some compare, required field validator and want to show the validation message in alert window. So I thought of using ShowMessageBox="true" in validationsummary. Message box is coming fine.
Later on I had to add a OnClientClick="javascript:return alertSid();" .
When I added this OnClientClick event my message box is not coming but validation is happening.
If I remove the OnClientClick event then again the message box is coming with validation summary message.

I even removed the whole code in javascript function just to check whether its because of some code mistake in java script. Even though its not coming.

Here is the code im using:

Name: <asp:TextBox runat="server" ID="txtName" ></asp:TextBox>

<asp:RequiredFieldValidator EnableClientScript="true" ID="rfvForName" runat="server" ControlToValidate="txtName"
Text="*" ErrorMessage="Please Enter Name"></asp:RequiredFieldValidator>

<asp:Button ID="btnOpenAlert" runat="server" Text="Alert" OnClientClick="javascript:return alertSid();" />

<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true" HeaderText="Error For the following"
DisplayMode="BulletList" ShowSummary="false" ShowMessageBox="true" />


function alertSid() {
return true;
sheena k 12-Sep-14 5:26am    
How to use validation summary in javascript validation for empty textbox control without requiredfieldvalidator in ASP.NET ??
Means when I set a OnClientClick="Javascript:return Validations()" on submit button,It is showing Single alert box validation but i want to show all summary of empty box in one alert it is possible Pls help me its urgent....thnxs in advance

1 solution

Hi Sid.Mup,

OnClientClick="javascript:return alertSid();"

OnClientClick="javascript: alertSid();"

the return statement is not allowing next function to execute.

FYI: the html generated for your button will be like this:

<input type="submit" name="btnOpenAlert" value="Alert" onclick="javascript: return alertSid(); ;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;btnOpenAlert&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="btnOpenAlert" />

The WebForm_DoPostBackWithOptions function is added by Asp.Net and the return statement of your function is not allowing it to execute hence to validation summary message.

Hope this will help.

Share this answer
Shahriar Iqbal Chowdhury/Galib 30-Apr-11 3:03am    
Good solution
Hemant__Sharma 2-May-11 0:17am    
Thank you.
Sid.Mup 30-Apr-11 9:07am    
Thank you soo much...It worked...
Hemant__Sharma 2-May-11 0:18am    
Happy to help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900