Saturday, March 31, 2012

Set a condition before following a hyperlink

In straightforward html I have used the following:-

<a onClick="return checkpass(Checkit.PassToForm.value);" href="http://links.10026.com/?link=myweb3/members.htm">Continue

where checkpass is a function that returns true or false and it has to be true before the user can access the next page.

Validation controls would not be an answer in this particular instance

I have not been able to do the same sort of thing in ASP. onclick = "return Somefunction"; href etc produces an error message "Somefunction isundefined"


In Asp, if the OnClick event is already defined for the webcontrol, then it is expecting a C# function handler. In this case, you will need to use OnClientClick.

I would suggest using a LinkButton. This will ensure that people are validated when going to the next page, cause if javascript is disabled then the link button wont redirect the user.

<asp:LinkButton ID="lb" runat="server" Text="Gohere" OnClientClick="return checkpass("myvalue")" />


You would need preventDefault.http://developer.mozilla.org/en/docs/DOM:event.preventDefault

But it is not supported in old browsers.


Hi

I think the checkpass function is some sort of a client side scripting function (probably javascript). If that is right I would suggest you to open the new page from the javascript function itself rather than using href.

Hope this helps to solve your problem

Good LuckYes

Regards

Vineed


Hi,

Mulozi:

<a onClick="return checkpass(Checkit.PassToForm.value);" href="http://links.10026.com/?link=myweb3/members.htm">Continue

You can redirect the page in the javascript function itself. So your fucntion checks the details and if correct it will transfer to another page.

use the below...

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function checkDetails()
{
if(document.getElementById("txt").value != "")
{
window.location.href="default2.aspx";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txt" runat="server"></asp:TextBox><br />
<a onclick="checkDetails();" href="http://links.10026.com/?link=http://forums.asp.net/AddPost.aspx?ReplyToPostID=1967328&Quote=False#"> Hi</a></div>
</form>
</body>
</html>


Thanks.

I should have mentioned that I am using VB for this application. Sorry to have put you to the trouble.

I seem to have succeeded in a previous application which used Javascript.

I have to use VB for this one and am trying to find the VB equivalent.

Thee must be an equivalent somehow using VB

I should also have mentioned that I have been using Visual Web Developer 2008 express edition


Thanks.

I haven't been able to succeed with this either

I should have mentioned that I am using VB for this application. Sorry to have put you to the trouble.

I seem to have succeeded in a previous application which used Javascript. and the previous example was Javascript .

I have to use VB for this one and am trying to find the VB equivalent.

There must be an equivalent somehow using VB

Can I not run a script from the command button which would include a conditional go to URL ... ?

I should also have mentioned that I have been using Visual Web Developer 2008 express edition

Any further thoughts gratefully received.


Thanks.

I presume preventDefault is Javascript

I should have mentioned that I am using VB for this application.

I seem to have succeeded in a previous application which used Javascript. and the previous example was Javascript .

I have to use VB for this one and am trying to find the VB equivalent.

There must be an equivalent somehow using VB

Can I not run a script from the command button which would include a conditional go to URL ... ? I have not found a way of doing it, but this must be a common enough requirement.

I should also have mentioned that I have been using Visual Web Developer 2008 express edition

Any further thoughts gratefully received.


Hi,

Are you trying to execute the function on the client-side or server side. If you can execute it on the server side, then instead of a hyperlink use a linkbutton and on the click event of it check the condition that you are looking out for and use Response.Redirect to the new page. That should possibly solve the problem.

Hope this solves your problem

Good LuckYes

Regards

Vineed

0 comments:

Post a Comment