Srikanth
Srikanth

Reputation: 35

How to find the Controls in panel (which is added through literal)

Textbox1.text is user can enter html page name, so that its is appending to panel through literal.(loading html page to pannel).

string val = TextBox1.Text;
string location = Server.MapPath(".");
string path = location + "\\HTML\\" + val + ".html"; // HTML IS FOLDER NAME IN MY PROJECT
string readText = System.IO.File.ReadAllText(path);
Panel1.Controls.Clear();
Literal lit = new Literal();                
lit.Text = readText;
Panel1.Controls.Add(lit);

Actually in Html page few controls which are in format of input (<input style="position: relative;" id="T0" onmouseup="mUp(this.id)" class="ui-draggable" onmousedown="mDown(this.id)" value="" type="text">) I have to find those id's and text to save in database. how to find the controls in panel now?

Upvotes: 0

Views: 4638

Answers (3)

Rajneesh
Rajneesh

Reputation: 2291

Since you did not give id to the control, u can find them by Panel1.Controls[index], since it is the first control added u can access at Panel1.Controls[0]

Upvotes: 0

nunespascal
nunespascal

Reputation: 17724

Give an ID to the control when you add it.

Literal lit = new Literal();                
lit.Text = readText;
lit.ID = "myLiteral";
Panel1.Controls.Add(lit);

Then you can get it back as follows:

Literal lit = (Literal)Panel1.FincControl("myLiteral");   

Remember that dynamically added controls must be created added again on every PostBack that follows as long as you want to have access to them.

Upvotes: 1

CoderMarkus
CoderMarkus

Reputation: 1118

Give your Literal an ID and then you can access it via FindControl...

Literal myLiteral = Panel1.FindControl("litId") as Literal;
if (myLiteral != null)
{
    // ... do something
}

EDIT: (Missed the last part of your question)

You need to use ParseControl([string value]) on the HTML content which returns a control and then add that control (containing all child controls) to the Panel. Then you can use FindControl to locate child controls. For this method, the controls must be .NET controls (ie.

Upvotes: 0

Related Questions