Loading ...

Get the .aspx code into string variable

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » Get the .aspx code into string variable

Get the .aspx code into string variable

Posts under the topic: Get the .aspx code into string variable

Posted: 10/22/2010

Lurker 115  points  Lurker
  • Joined on: 10/11/2010
  • Posts: 15

Dear Friends,

I want to get the .aspx code into string variable during .aspx.cs file loading.

    protected void Page_Load(object sender, EventArgs e)
    {
        string condent = "";

Is it possible?

Suresh


Posted: 10/22/2010

Professional 8338  points  Professional
  • Joined on: 4/15/2009
  • Posts: 424

What exactly do you meant by .aspx code? do you want to get the control value in the aspx? Please be more specific so that we can assist you easily.

Thanks.


Posted: 10/22/2010

Lurker 115  points  Lurker
  • Joined on: 10/11/2010
  • Posts: 15

test.aspx

 

<body>
    <form id="frmTest" runat="server">
    <div>
        <asp:Label ID="lblTest" runat="server" Text="Test Name"></asp:Label><br />
    </div>
    </form>
</body>


test.aspx.cs

 

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string condent="";

        if (!IsPostBack)
        {
            lblTest.text="Dimensional Test Report";
            condent=????? //get the code of test.aspx
        }
    }


expected result with all tags in variable

<body>
    <form id="frmTest" runat="server">
    <div>
        Dimensional Test Report
    </div>
    </form>
</body>


Thanks,

Suresh


Posted: 10/22/2010

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Why do you need it at that place ?


Posted: 10/22/2010

Lurker 115  points  Lurker
  • Joined on: 10/11/2010
  • Posts: 15

To send by html email and save a copy into the database.

Regards,

Suresh


Posted: 10/22/2010

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

The do in some button's click event handler, why you are going in Page Load event.


Posted: 10/22/2010

Lurker 115  points  Lurker
  • Joined on: 10/11/2010
  • Posts: 15

Sir,

Any idea to do in button click event.

Suresh


Posted: 10/22/2010

Professional 8338  points  Professional
  • Joined on: 4/15/2009
  • Posts: 424
  Answered

@Suresh,

Perhaps, you were looking for this: http://west-wind.com/weblog/posts/481.aspx


Posted: 10/22/2010

Professional 8505  points  Professional
  • Joined on: 5/3/2010
  • Posts: 391
  Answered

Vinz said:

user="Vincent Maverick Durano"]

@Suresh,

Perhaps, you were looking for this: http://west-wind.com/weblog/posts/481.aspx

Referring to the Link that Vinz posted, the minimal code you need to write to achieve this would be:

        protected void Page_Load(object sender, EventArgs e)
        {
            string condent="";

            if (!IsPostBack)
            {
                lblTest.Text="Dimensional Test Report";
                StringBuilder b = new StringBuilder();
                StringWriter strWriter = new StringWriter(b);
                HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter);
                base.Render(htmlWriter);
                condent = b.ToString();
            }
        }

Read the complete article in the link posted by Vinz.


Posted: 10/22/2010

Lurker 115  points  Lurker
  • Joined on: 10/11/2010
  • Posts: 15

Thanks Hajan,

But, I am getting an error.

Compiler Error Message: CS0246: The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

I am using VS 2005.

Suresh


Posted: 10/22/2010

Professional 8338  points  Professional
  • Joined on: 4/15/2009
  • Posts: 424
  Answered

Declare the the namespace below:

using System.Text;

 


Posted: 10/22/2010

Lurker 115  points  Lurker
  • Joined on: 10/11/2010
  • Posts: 15

StringBuilder OK.

Again, I am getting the error on StringWriter.

 

Compiler Error Message: CS0246: The type or namespace name 'StringWriter' could not be found (are you missing a using directive or an assembly reference?)


Thanks,

Suresh


Posted: 10/22/2010

Professional 8505  points  Professional
  • Joined on: 5/3/2010
  • Posts: 391
  Answered

Yes, as Vinz said, you need to have the System.Text; namespace directive.

Also if you don't, you need to add the System.IO; namespace too.


Posted: 10/25/2010

Lurker 115  points  Lurker
  • Joined on: 10/11/2010
  • Posts: 15

Dear Friends,

Thank you so much.

Suresh


Posted: 10/25/2010

Professional 8505  points  Professional
  • Joined on: 5/3/2010
  • Posts: 391

vagaisuresh said:

user="suresh v"]

Dear Friends,

Thank you so much.

Suresh

You are always welcome Wink


Page 1 of 1 (15 items)