简体   繁体   English

从.aspx返回值到.aspx.cs

[英]Return value from .aspx to .aspx.cs

I'm passing the value of a variable in my.aspx.cs file to my .aspx file. 我正在将my.aspx.cs文件中的变量值传递给我的.aspx文件。 When its in the aspx, the value of it gets changed and then needs to be returned back to the .aspx.cs file. 当它在aspx中时,它的值会更改,然后需要返回到.aspx.cs文件。 However, it won't let me change the value of the variable. 但是,它不会让我更改变量的值。 Any suggestions? 有什么建议么?

.cs 的.cs

       private string dateLookup;
    public string DateLookup
    {
        get { return dateLookup; }
        set { dateLookup = value; }
    }

.aspx 的.aspx

    <script runat="server">
    void Selection_Change(Object sender, EventArgs e)
    {
       "<%=DateLookup %>" = monthList.SelectedItem.Value;
    }

</script>

You can assign the property like any other property: 您可以像其他任何属性一样分配该属性:

DateLookup = something;

The <%= ... %> syntax is used to print any value on to the page. <%= ... %>语法用于将任何值打印到页面上。

the event should also be in your code behind (cs) 该事件也应该在您的代码后面(cs)

void Selection_Change(Object sender, EventArgs e)
{
    DateLookup = monthList.SelectedItem.Value;
} 

the <%=DateLookup %> notation does not assign something, it outputs it to the html <%= DateLookup%>表示法没有分配任何内容,而是将其输出到html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM