Navigation control

4 posts, 2 answers
  1. Moon
    Moon avatar
    249 posts
    Member since:
    Oct 2012

    Posted 27 Aug 2008 Link to this post

    We have the Q1 2008 ASP.net controls and the Q2 2008 Ajax controls.

    Do you have something that would do this:

    I want to display something like a linkbutton. and set an onClientClick event so that it runs a function, and if that function is true, it sends the user to the URL, and if false, it keeps them on the page without doing a postback.

    Do you have anything that does this?

    I've tried with the hyperlink and the linkbuttons and they just don't do it so I'm hoping you have something in your toolbox that works like this.

    thanks.
  2. Answer
    Shaun Peet
    Shaun Peet avatar
    571 posts
    Member since:
    Aug 2004

    Posted 27 Aug 2008 Link to this post

    Hello,

    Try something like this:

        <script type="text/javascript" language="javascript">
          var dummy = 0;

          function customClickFunction() {
            if (dummy == 1) {
              window.location = "http://www.google.com";
            }
            else {
              alert("Nothing happening yet.  Click again!");
              dummy += 1;
            }
          }
        </script>
        <a href="javascript:customClickFunction()">Click Here!</a>



    Hope that helps,

    Shaun.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Shaun Peet
    Shaun Peet avatar
    571 posts
    Member since:
    Aug 2004

    Posted 27 Aug 2008 Link to this post

    As an aside, just about every Telerik control will be capable of accomplishing what you're after using it's client-side programming features - the only "trick" here is getting the client-side function to execute in the first place.  If you know which of the Telerik controls you'd like to use for this purpose, let me know and I'll update the example to use that control.

    For example, if you want to use RadMenu, you would set the OnClientItemClicked="customClickFunction", and slightly alter the javascript function to accept two parameters:

    function customClickFunction(sender, args) { ... }

    Like I said, nearly every Telerik ASP.NET or ASP.NET AJAX control will allow you to set some client-side function to be executed with certain interation events.  Although, as my example demonstrates, you don't necessarily even need a Telerik control to accomplish what you're after.

    I'm assuming that when you said "runs a function" you meant on the client-side.  If you want to run a server side event then let me know and I can provide an example of how to do that.

    Hope that helps,

    Shaun.
  5. Moon
    Moon avatar
    249 posts
    Member since:
    Oct 2012

    Posted 27 Aug 2008 Link to this post

    Thanks for the suggestions. I did ultimately find the solution to the linkbutton problem. My javascript had to return false on all paths and take them to the url within the javascript if the answer should be true.

    thanks!
Back to Top