如何从.aspx页调用.cs页中的方法 [英] How to call a method in .cs page from .aspx page

查看:70
本文介绍了如何从.aspx页调用.cs页中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个文本框和一个ajax日历,如下所示:

I have a text box and a ajax calender in my project as below:

<asp:TextBox ID="txtDOB" runat="server"></asp:TextBox>
                <cc1:CalendarExtender ID="DOBCalendarExtender" TargetControlID="txtDOB" runat="server"

                    Format= "<%# DisplayUserDateFormat()%>" PopupButtonID="DOBImageButton" OnClientDateSelectionChanged="checkDate">
                </cc1:CalendarExtender>



并且我已经在相应的.cs文件中定义了方法"DisplayUserDateFormat",如下所示:



and I have defined the method "DisplayUserDateFormat" in the corresponding .cs file as below:

public string DisplayUserDateFormat()
    {
        String strDob = "dd-MMM-yyyy";
        return strDob ;
    }



但是,当我在此方法上设置断点时,不会被调用.
谁能告诉我为什么会这样?



But, when I set a breakpoint on this method, it is not getting called.
Can anyone tell me why it is happening?

推荐答案

尝试:Format =<% = DisplayUserDateFormat()%>"
Try: Format= "<%=DisplayUserDateFormat()%>"


对不起,<%= DisplayUserDateFormat()%>"仅适用于非服务器标签.

您必须使用PageMethods来执行所需的操作.

检查此 http://www.dotnetcurry.com/ShowArticle.aspx?ID=109&AspxAutoDetectCookieSupport= 1 [ ^ ]
Sorry, "<%=DisplayUserDateFormat()%>" only works with non-server tags.

You have to use PageMethods to do what you want.

Check this http://www.dotnetcurry.com/ShowArticle.aspx?ID=109&AspxAutoDetectCookieSupport=1[^]


您正在使用数据绑定语法...您实际上在页面中调用Databind()吗?

我通常在PreRender事件上执行此操作.
You''re using databinding syntax...are you actually calling Databind() in your page?

I usually do it on the PreRender event.


这篇关于如何从.aspx页调用.cs页中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆