?
Solved

javascript and vb.net (button click)

Posted on 2011-09-17
6
Medium Priority
?
312 Views
Last Modified: 2012-08-13
i curently have a javascript code that will run a script to show contect within a div onclick...
<script type="text/javascript" >
    $(function () {
        $(".submit").click(function () {
            var comment = $("#textbox").val();
            var dataString ='&comment=' + comment;
            if (comment == '') {
                alert('Please Give Valid Details');
            }
            else {
                $("#flash").show();
                $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" />Loading Comment...');
                $.ajax({
                    type: "POST",
                    url: "Default2.aspx",
                    data: dataString,
                    cache: false,
                    success: function (html) {
                        $("div#update").append(html);
                        $("div#update li:last").fadeIn("slow");
                        $("#flash").hide();
                    }
                });
            } return false;
        });
    });

    </script>

Open in new window


is there away i can chnage this javascript so i can just call it via  submit.Attributes.Add("onClick", ***run the code somehow here***")
0
Comment
Question by:runnerjp2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 36554682
submit.Attributes.Add("onClick", "trig1()")

with :



<script type="text/javascript" >
	$(function () {
		$(".submit").click(trig1);
	});
	function trig1() {
		var comment = $("#textbox").val();
		var dataString ='&comment=' + comment;
		if (comment == '') {
			alert('Please Give Valid Details');
		}
		else {
			$("#flash").show();
			$("#flash").fadeIn(400).html('<img src="ajax-loader.gif" />Loading Comment...');
			$.ajax({
				type: "POST",
				url: "Default2.aspx",
				data: dataString,
				cache: false,
				success: function (html) {
					$("div#update").append(html);
					$("div#update li:last").fadeIn("slow");
					$("#flash").hide();
				}
			});
		}
	}
</script>

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 36554686
but I think you want this (remove/without submit.Attributes.Add("onClick", ***run the code somehow here***")) :
<script type="text/javascript" >
    $(function () {
        $(".submit,#submit").click(function () {
            var comment = $("#textbox").val();
            var dataString ='&comment=' + comment;
            if (comment == '') {
                alert('Please Give Valid Details');
            }
            else {
                $("#flash").show();
                $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" />Loading Comment...');
                $.ajax({
async:false,
                    type: "POST",
                    url: "Default2.aspx",
                    data: dataString,
                    cache: false,
                    success: function (html) {
                        $("div#update").append(html);
                        $("div#update li:last").fadeIn("slow");
                        $("#flash").hide();
                    }
                });
            } return false;
        });
    });

    </script>

Open in new window

0
 
LVL 7

Expert Comment

by:Kishan Zunjare
ID: 36555901
Create Javascript function of you code and provide following in asp.net code behind;

On the page load event
Button1.Attributes.Add("onclick","JS FunctionName()");

Hope this will work.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:runnerjp2005
ID: 36556633
leakim971: i dont understand the 2nd post?
0
 

Author Comment

by:runnerjp2005
ID: 36556642
my main issue is the javascript means i cant run
 Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
        Label1.Text = "hello"
    End Sub

it does the javascript part and misses the onlick ...yet i need both!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36556735
>leakim971: i dont understand the 2nd post?

we use a synchronous ajax call (line 13) : http://arshadinfo.wordpress.com/2008/05/25/what-is-the-difference-between-asynchronous-ajax-and-synchronous-request/

>my main issue is the javascript means i cant run
>Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
>        Label1.Text = "hello"
>    End Sub
>it does the javascript part and misses the onlick ...yet i need both!

Yes, that's why I propose the second code. First we need to wait end of the ajax call
If you want to run your server side code ( Label1.Text = "hello" ) you must remove the return false;

Note you don't need : submit.Attributes.Add("onClick", "trig1()")
and $(".submit").click(trig1); // if .submit is the class of your button
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

764 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