Solved

Javascript to raise an form click event, asp.net 3.5 C# , VS 2010

Posted on 2013-01-10
4
468 Views
Last Modified: 2013-02-13
Hi,

When i click Server control "Save" button ...

using JavaScript, i want to generate an event as if i clicked on form area (not on any control in the form) before execution of the "save: button code.

Thanks
0
Comment
Question by:kishan66
  • 2
4 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 250 total points
ID: 38763620
can you elaborate your question?
when exactly do you want to generate a click event on client side?
0
 

Author Comment

by:kishan66
ID: 38763684
hi sedgwick,

Assume i enter some thing in a textbox (control within form) ....my focus is still in textbox.
now when i click on "Save" button (which is in a ribbon control).. using javascript, i want to loose focus of that textbox (inthis example) and then submit the form.

Problem : when my focus is still in textbox , even if i click save the changed text value is not retained  when the form is submitted.

works fine when i click on anyother control or any where else on form.
0
 
LVL 18

Assisted Solution

by:Rajar Ahmed
Rajar Ahmed earned 250 total points
ID: 38763730
Are you lookin like this , ?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>
        function validate() {
            if (document.getElementById("TextBox1").value == "") {
                alert("Please Enter Name");
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Name :<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br />
        <asp:Button ID="Button1" runat="server" Text="Button" 
            OnClientClick="return validate();" onclick="Button1_Click" />

    </div>
    </form>
</body>
</html>

Open in new window


   protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("Hi" + TextBox1.Text);
    }

Open in new window

0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38763749
Hi kishan66,

skip my previous comment .
Post the code which can show your issue .
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question