[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 138
  • Last Modified:

Problem to call the event

Hi,
Using these
                <div class="imagesList-item-frame shadow">
                    <img src="..." onclick="ite_click6" />
                </div>

        protected void ite_click6(object sender, EventArgs e)
        {
            ...

Open in new window

but the event is not fired when I click the iteure on the page. why?

BTW, how to also call one other event, whenever the mouse is "just" over the area of the iteure.
0
HuaMinChen
Asked:
HuaMinChen
  • 6
  • 4
  • 2
  • +1
1 Solution
 
Alexandre SimõesManager / Technology SpecialistCommented:
You're mixing client-side events with server-side events and controls.

That image element you have there is not a server-side control so it won't fire any server-side events.
Also, that onclick is expecting to find a javascript function called ite_click6 which you don't have.

So either handle the click on javascript or change the image element into a server-side control and handle the click with the proper OnClick server-side event.
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Thanks. can I have the details to further call one code-behind event, within the javascript event below?

    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script type="text/javascript">
        function event2() {
            ...
        }
    </script>

Open in new window

0
 
Alexandre SimõesManager / Technology SpecialistCommented:
You can't just fire the event like that but you can call a method on your page via ajax for instance using jQuery.

What do you want to do when you call that server-side function?
0
Industry Leaders: 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!

 
HuaMinChenBusiness AnalystAuthor Commented:
To further call one other .aspx page within another browser window.
0
 
Alexandre SimõesManager / Technology SpecialistCommented:
call one other .aspx page within another browser window
What does this mean?
Open another page in a new window?
0
 
Ray PaseurCommented:
The basics of jQuery and AJAX are shown in this article.  It uses PHP for the server side, but the principles would be equally applicable to any server-side scripting language.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html
0
 
Slick812Commented:
greetings HuaMinChen, , I am not sure I understand what your problems are from what I can get reading through this. In your initial code you have  -
     <img src="..." onclick="ite_click6" />


so The EVENT you talk of is the user touching the image on their smart phone? ? is that right?

and you say you need to have this touch event open another tab in the phone browser that has a different asp page in it. I do not think that this needs any ajax, you just have to have your javascript   ite_click6() function to do this? ?

but maybe I do not really see what the end result is for your touch-click event for this image?
0
 
Slick812Commented:
just remembered, if you only need to open a new tab-window for an image you might try something like -
    <a target="_blank" href="http://google.com" title="Google Search"><img src="googleIcon.jpg" /></a>

if you need to do more with some javascript variables or page elements, you can do an onclick function for the image
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Ray/Alexandre/Slick,

Like what I originally asked, I only want to see one sample, that is calling either one Ajax event or code-behind event, upon one click to the image on the page.
0
 
Alexandre SimõesManager / Technology SpecialistCommented:
Here you go:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

I'll copy the relevant code here as reference but you should read the full article.

In your page create the static method you want to call and decorate it with the WebMethod attribute:
public partial class _Default : Page 
{
  [WebMethod]
  public static string GetDate()
  {
    return DateTime.Now.ToString();
  }
}

Open in new window

To call the method via ajax it's easier to use jQuery and you can do so as follows:
$.ajax({
  type: "POST",
  url: "PageName.aspx/MethodName",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Do something interesting here.
  }
});

Open in new window

0
 
HuaMinChenBusiness AnalystAuthor Commented:
Thanks. Within the WebMethod, is it possible for me to further direct to one other page like

Response.Redirect("http://192.168.168.1/Showite/Default.aspx");

Open in new window


?
0
 
Alexandre SimõesManager / Technology SpecialistCommented:
Not like that because you're not in the process of a page post-back.
What you can do is send the url as a reply to that ajax code and use window.location.href to perform the redirection on the client side.
public partial class _Default : Page 
{
  [WebMethod]
  public static string DoMyStuff()
  {
    return "http://192.168.168.1/Showite/Default.aspx";
  }
}

Open in new window

$.ajax({
  type: "POST",
  url: "PageName.aspx/DoMyStuff",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(resp) {
    if(resp){
        window.location.href=resp;
    }
  }
});

Open in new window

As a rough example it should work.
0
 
Ray PaseurCommented:
...I only want to see one sample, that is calling either one Ajax event or code-behind event, upon one click to the image on the page.
That is exactly what you would have found if you had read the article linked here:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html

This is a very common question and you're not the first to ask!  That's why we have an article system here at E-E.  If you just make a search of the articles you will find many useful descriptions and examples for the most common programming questions.
0
 
Alexandre SimõesManager / Technology SpecialistCommented:
Calm down Ray :)

Although the article is fine for client-side, the server-side "code" doesn't resemble at all to anything he needed to write to make it work in ASP.net. So in my opinion your bold italic whatever "exactly" is a bit off... :)

As the code client-side is the same, and if you really want to push it that hard for solutions, a good update to that article would be to add the .net version of it.

Cheers!
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 6
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now