This is a migrated thread and some comments may be shown as answers.

Navigation control

3 Answers 72 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Moon
Top achievements
Rank 2
Moon asked on 27 Aug 2008, 04:11 PM
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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Shaun Peet
Top achievements
Rank 2
answered on 27 Aug 2008, 06:18 PM
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.
0
Accepted
Shaun Peet
Top achievements
Rank 2
answered on 27 Aug 2008, 06:27 PM
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.
0
Moon
Top achievements
Rank 2
answered on 27 Aug 2008, 08:07 PM
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!
Tags
General Discussions
Asked by
Moon
Top achievements
Rank 2
Answers by
Shaun Peet
Top achievements
Rank 2
Moon
Top achievements
Rank 2
Share this question
or