---
title: "ASP.NET is not calling C# code"  
description: "ASP.NET is not calling C# code"  
author: "Mark M"  
published: 2014-12-08  
updated: 2014-12-09  
canonical: https://www.mindstick.com/forum/12767/asp-dot-net-is-not-calling-c-sharp-code  
category: "asp.net"  
tags: ["c#"]  
reading_time: 1 minute  

---

# ASP.NET is not calling C# code

For some reason this following [ASP](https://www.mindstick.com/articles/751/introduction-to-asp-dot-net-mvc) [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) is not calling the c# method "checkLastNames" that is suppose to be evaluated in the 'Visible=' [field](https://www.mindstick.com/forum/160867/does-mindstick-provide-training-for-field-marketing) below.

```
<asp:Button ID="btnZ"             runat="server"             Text="Z"             Height="20px"             Width="25px"             Font-Size="12px"             CommandArgument="Z"             OnClick="btnA_Click"             Visible='<%# checkLastNames("Z") %>' />
```

When I enter [debug mode](https://www.mindstick.com/interview/23356/how-can-you-test-bundling-in-debug-mode) the method isn't even being called. Visible just defaults to true. I've tried changing the [method to return](https://www.mindstick.com/forum/55125/how-to-create-generic-method-to-return-multiple-list-in-c-sharp) only false just to see if it would work but "Visible" is still defaulting to true.

```
protected bool checkLastNames(string s){    return false;}
```

## Replies

### Reply by Takeshi Okada

Try like this

```
<asp:Button ID="btnZ" runat="server" Text="Z"            
Height="20px"            
Width="25px"            
Font-Size="12px"            
CommandArgument="Z"            
OnClick="btnA_Click"            
Visible='<%= checkLastNames("Z") %>' />
```

### Reply by Anonymous User

<%# is for databinding expressions, so this works only if the namingcontainer control of this Button is databound.

For example in Page_Load:

this.DataBind();

But why not using codebehind in the first place?

btnZ.Visible = checkLastNames("Z");


---

Original Source: https://www.mindstick.com/forum/12767/asp-dot-net-is-not-calling-c-sharp-code

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
