Posted: 10/22/2010
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
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.
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,
Why do you need it at that place ?
To send by html email and save a copy into the database.
Regards,
The do in some button's click event handler, why you are going in Page Load event.
Sir,
Any idea to do in button click event.
@Suresh,
Perhaps, you were looking for this: http://west-wind.com/weblog/posts/481.aspx
Vinz said: user="Vincent Maverick Durano"]@Suresh,Perhaps, you were looking for this: http://west-wind.com/weblog/posts/481.aspx
user="Vincent Maverick Durano"]
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(); } }
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?)
Declare the the namespace below:
using System.Text;
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?)
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
Thank you so much.
vagaisuresh said: user="suresh v"]Dear Friends,Thank you so much.Suresh
user="suresh v"]
You are always welcome