Home > DeveloperSection > Forums > ASP.NET is not calling C# code
Kamlakar Singh
Kamlakar Singh

Total Post:28

Points:196
Posted on    December-08-2014 10:33 PM

 ASP.Net C# 
Ratings:


 2 Reply(s)
 556  View(s)
Rate this:

For some reason this following ASP code is not calling the c# method "checkLastNames" that is suppose to be evaluated in the 'Visible=' field 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 the method isn't even being called. Visible just defaults to true. I've tried changing the method to return only false just to see if it would work but "Visible" is still defaulting to true.

 

protected bool checkLastNames(string s){

    return false;

}



ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    December-09-2014 6:02 AM

<%# 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");


Takeshi Okada
Takeshi Okada

Total Post:89

Points:629
Posted on    December-09-2014 7:08 AM

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") %>' />


Don't want to miss updates? Please click the below button!

Follow MindStick