Click here to Skip to main content
16,009,185 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to write event in Code behind file for onclick event of anchor tag using c# code.

<a id="ascaleUpgarde" runat="server" önclick="fnSetNewControls" href="~/frmSignOn.aspx" >Scale Upgrade


how to write event in C# for onclick.
Note: I dont want to use javascript.
Posted
Comments
F-ES Sitecore 9-Dec-15 9:09am    
Assuming you want the code to fire before the browser redirects to frmSignOn you'll need to make the page link to itself and add a parameter of some sort, then in the page_load of the page detect the parameter is there, do the work you want to do and then response.redirect to frmSignOn. That is the only way of doing this without using javascript (LinkButton etc uses js).
Richard Deeming 9-Dec-15 10:25am    
This is a question from 2012. It got dragged back into the list by Solution #4.

try this one also it will work :)

ASP.NET
<a id="ascaleUpgarde" runat="server">
 href="#">Scale Upgrade</a>

and in the code behind write this 


C#
protected void Page_Load(object sender, EventArgs e)
{
    ascaleUpgarde.ServerClick +=new EventHandler(fnSetNewControls_Click);
}
protected void fnSetNewControls_Click(object sender, EventArgs e)
{
    Response.Write("<script>alert('test')</script>");
}
 
Share this answer
 
Hey,
try following to do this
Hello
and in page load write following code
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["i"] == "1")
{
Anchor_Click(sender,e);
}
}

//write this manually
protected void Anchor_Click(object sender, EventArgs e)
{
Response.Write("Hi");
}

Best Luck
 
Share this answer
 
Comments
Member 11280099 21-Mar-16 2:59am    
Hello sir,
I want to call a method by an anchor tag and the anchor tag is written at aspx.cs file with innerhtml.
For exapmle--
DivId.InnerHtml=InnerHtml+ "< a href='#' runat="server" > Clickme < /a >";
This code is written at aspx.cs file.
Please guide me how to call a server side method by this anchor tag.
I suggest instead of an anchor tag you switch to linkbutton. that will give the look and behavior of the anchor tag and have the possibility of having a serverside click.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900