1

i have following code in a String variable at run-time

<form runat="server">

    <asp:textbox runat="server"
        ID="a1"
        Text="enter text here"
    />
    <asp:button runat="server"
        Text="enter text here"
    />
    <br />
</form>

so how can i run it to at run time on a new page by clicking on some button or so?
earliest help will be highly appreciated.

7
  • can you be a bit more specific? Commented Mar 9, 2013 at 15:54
  • okay, the above code is created and stored in a String variable at run-time. now, i want to run that code. how can i do that. HTML code can be put in LITERAL. and run. how can this be donw on ASP>Net counterpart? Commented Mar 9, 2013 at 16:00
  • You can't use asp.net controls as string variable. Consider using pure HTML objects or change the concept, like adding specific asp.net controls to something like PlaceHolder. Commented Mar 9, 2013 at 16:00
  • i am not using asp.net control as string variable. ok lets say, how can i run the asp.net code from certain text file at runtime/? Commented Mar 9, 2013 at 16:10
  • Yea... not going to happen, at least not how you're suggesting. Put this code into a user control, and pass the control name as a string instead. Commented Mar 9, 2013 at 16:56

2 Answers 2

1

You mentioned loading from a text file. I think you should review usercontrols. It is the preferred method to load asp.net content and controls from an included file.

http://msdn.microsoft.com/en-us/library/y6wb1a0e(v=vs.100).aspx

Sign up to request clarification or add additional context in comments.

1 Comment

no, no! the above code is stored in a text file. i want to run it at runtime.
0

Put this code into a user control, and pass the control name as a string instead.

void Page_Init(object sender, System.EventArgs e)
{
    //your string
    string controlName = "TempControl_Samples1.ascx.cs";

    // instantiate usercontrol object
    MyControl myControl1 = (MyControl)LoadControl(controlName);
    PlaceHolder1.Controls.Add(myControl1);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.