Solved

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

Posted on 2013-01-10
4
467 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

839 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