开发者

asp.net - display data in ascx dynamically from results in c# document

开发者 https://www.devze.com 2023-03-12 05:50 出处:网络
I have a cs document that dynamically changes values depending on array size: size =something.length; if(size==1)

I have a cs document that dynamically changes values depending on array size:

size =something.length;
if(size==1)
{
something1="a";
}
if(s开发者_Python百科ize==2)
{
something2="b";
}
etc....

In the ascx file I want to display the results dynamically based on the array size in the CS file.

 <asp:Label ID=something1 runat=serve></asp label>
 <asp:Label ID=something2 runat=serve></asp label>
 <asp:Label ID=something3 runat=serve></asp label> ....etc

How would I do this?


size =something.length;
if(size==1)
{
something1.Text = "a";
}
if(size==2)
{
something2.Text = "b";
}
etc....


I believe he wants the labels inside a user control to be updated based on the parent page. Here is an example of that.

Default Page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="uc1" TagName="WebUser" Src="WebUserControl.ascx" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:WebUser runat="server" ID="ucMyControl" />

    </div>
    </form>
</body>
</html>

Code Behind

ucMyControl.TextToShow = "My Text";

User Control

<asp:TextBox ID="txtMyText" runat="server"></asp:TextBox>

User Control Code Behind

 private string m_textToShow;

    public string TextToShow
    {
        get
        {
            return m_textToShow;
        }
        set
        {
            m_textToShow = value;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        this.txtMyText.Text = m_textToShow;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消