Click here to Skip to main content
16,021,449 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
JavaScript
<script type = "text/javascript">

    function Confirm()
    {
        var confirm_value = document.createElement("INPUT");
        confirm_value.type = "hidden";
        confirm_value.name = "confirm_value";
        if (confirm("Do you want to save data?")) {
            confirm_value.value = "Yes";
        } else {
            confirm_value.value = "No";
        }
        document.forms[0].appendChild(confirm_value);
    }

</script>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox1" runat="server" BackColor="White" BorderColor="White" 
BorderStyle="Groove" Width="157px"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" style="font-size: medium; font-weight: 700; font-style: italic" Text="Submit" onclick="Button1_Click" OnClientClick="Confirm()" />


I am using this code when click on Submit Button MessageBox is appear but it does not check Required Field Validator.
Posted
Updated 21-Apr-14 4:48am
v3
Comments
Sergey Alexandrovich Kryukov 20-Apr-14 12:51pm    
What are you trying to achieve and how? Why this strange code?
—SA
I can't see any RequiredFieldValidator in your posted code.
ALLAMI Said 21-Apr-14 11:52am    
The code written in the function Confirm() is executed before Button1_Click().
Do you get validation message when you remove Confirm() ?
Member 10701238 22-Apr-14 11:06am    
@ALLAMI yes, but how to call this function Confirm() in c# at button click

protected void Button1_Click(object sender, EventArgs e)
{

}

please write full code

1 solution

I think you want to show the message box after required field validater validates the input.
Call the Confirm() function from onsibmit of the form instaed of calling it from onClientClick.
Do a little change in your code as below;

ASP.NET
<form id="form1" runat="server" onsubmit="Confirm()><br mode=" hold=" /></form></pre><br mode="></form>
 
Share this answer
 

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