ASP.NET access to external servers inside the panel

I have a custom control that inherits from Panel. In boot mode, I want to access all the controls inside this panel, including non-server controls, for managing attributes. The Controlspanel property gives me server controls, but not server controls. Is there any way to access them?

For instance:

<cc:MyPanel runat="server">
    <asp:TextBox id="txt1" runat="server" />
    <input type="text" id="txt2" />
</cc:MyPanel>

During an event Load(or indeed any event before rendering a control) I want to manipulate both text fields.

thank

+3
source share
2 answers

runat='server' , JavaScript . .

:

<input id="txt2" runat="server" type="text" />

:

string s = txt2.Text;

, , - , , Request. , . , , .

, JS-, MSDN, , : http://msdn.microsoft.com/en-us/library/3hc29e2a.aspx

+4

RegisterStartupScript. , , , .

<asp:Panel ID="customPanel1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
    <input type="text" id="clientSideInput1" /><br />
    <input type="text" id="clientSideInput2" /><br />
</asp:Panel> 

protected void Page_Load(object sender, EventArgs e)
{
    var controls = customPanel1.Controls;
    foreach(Control c in controls)
    {
        if (c.GetType() == typeof(TextBox))
            ((TextBox)c).Text = "It worked!";
    }
    if (!Page.ClientScript.IsClientScriptBlockRegistered(GetType(), "PageScripts"))
    {
        var jscript = "document.getElementById('clientSideInput1').style.background=\"Red\";";
        jscript += "document.getElementById('clientSideInput2').style.background=\"Yellow\";";
        Page.ClientScript.RegisterStartupScript(GetType(), "PageScripts", jscript, true);
    }
}

...

enter image description here

, !

0

Source: https://habr.com/ru/post/1792262/


All Articles