[RESOLVED] call the code begind method in a aspx page

hello,

       how can we call the code begind method in a aspx page?

for ex:

code behind:

==========

public bool sample()
        {
            return true;
        }

 

aspx:

===========

<asp:CheckBox ID="chkPFCeilingFlag" runat="server" TabIndex="15" Checked='<%# sample() %>'
Enabled="true" CssClass="CheckBox"></asp:CheckBox>

but it is not called.

 

hi,

 this.chkPFCeilingFlag.DataBind();

 bcos this '<%# sample() %>' code will be executed while calling databind()

Hello,


You can set the Checked property of CheckBox on PageLoad event like this:

<asp:CheckBox ID="chkPFCeilingFlag" runat="server" TabIndex="15" Enabled="true" CssClass="CheckBox"></asp:CheckBox>


<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        If Not Page.IsPostBack Then</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            chkPFCeilingFlag.Checked = sample()</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        End If</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">    End Sub</div>

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!Page.IsPostBack)

        { 

              chkPFCeilingFlag.Checked = sample();

        }

    }


Please mark as Answer if it helps you.....Nitesh Garg

As the two people above me have stated, when you use <%# %>, it will perform these actions on the databinding event for the containing control.

I don't see why you would actually want to do it like this and not in the code behind, as this just seems to be a sloppy method to achieve whatever it is that you want.

Seeing as this isn't a dynamic control inside a template for a gridview/dataview/... you should probably just set the value in the page_load event.

you have to call chkPFCeilingFlag.DataBind() in page Load event

thanks


As per looking your code I dont understand what is the requiremet to write this kind of code in aspx page that you can achieve easily by writing it in page_load event.

 

But anyways...  Checked='<%# sample() %>' this want works to achieve from aspx page you can do it from javascript by following code.

function AlertMessage() {


            if ('<%=sample() %>' == 'True');
            {
               document.getElementById('chkPFCeilingFlag').checked = 1;
                

            }
        }


After that you need to call this function after in your page but make sure call this function in after your control load mean write this function exection code after the checkbox conrols aspx code (by line no)

 

Mark as answer if this answer for your question

nice.it is worked.if that function is in another one class then how can we call it.


If your current problem has been solved, mark the thread as resolved or mark the post as an answer. Start a new thread for new question.

The javascript method is not the best approach, as you know what you want to render, and it won't work is javascript is turned of.

server controls (those with a runat=server) only support binding expressions. if you want to use binding expressions, for a page where the controls are not in a repeater, etc, in page load you can just call:

  Page.DataBind();

if you want more control, (say you have a repeater), just wrap the controls you want to databind, in a panel, then call databind() on the panel in page load.

  pnlName.DataBind();

of course you could just call databind on the one control.

 cntName.DataBind()

and any expressions on it will work.


thoughts on "[RESOLVED] call the code begind method in a aspx page"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>