ACP
ACP

Reputation: 35268

Anchor tag onclick to call a code behind method

I use <a href="javascript:void(0);" onclick="orgvalid();return false;" class="regular">Register</a> in my aspx page. Once true is returned from the function orgvalid() I want to call a code behind function, insertorganization(). Is it possible to do so? If so, how?

Upvotes: 2

Views: 26719

Answers (5)

junmats
junmats

Reputation: 1924

<a href="#" onclick="insertOrganization();return false;" class="regular">Register</a>

InserOrganization Function:

function InsertOrganization(){
  if(orgvalid()){
     //do your thing here
  }
  else
    alert("not valid");
}

function orgvalid(){
  if({condition for true})
    return true;
  else
    return false;
}

Upvotes: 5

Krishna
Krishna

Reputation: 21

<a href="?i=1" id ="a" runat = "server">

on Page_load()
if (Request.QueryString["i"] == "1")
{
//call ur code here
AreaFootPrint_Click(null,null);
}

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038850

You could use a LinkButton instead:

  <asp:LinkButton id="RegisterButton"
   Text="Register"
   OnClientClick="return orgvalid();"
   OnClick="Register_Click"
   runat="server" />

and in the Register_Click server function you could call the insertorganization method.

Upvotes: 3

Quentin
Quentin

Reputation: 943579

if (orgvalid()) { insertorganisation(); } return false;

Upvotes: 0

o.k.w
o.k.w

Reputation: 25810

You should use a LinkButton instead

    <asp:LinkButton ID="LinkButton1" CommandName="somecommandname" 
runat="server" OnCommand="insertorganization" 
CommandArgument="some praram">
Register
</asp:LinkButton>

To note that this will perform a postback.

Upvotes: 1

Related Questions