Home
Manage Your Code
Snippet: Overload Render move VIEWSTATE to bottom (C#)
Title: Overload Render move VIEWSTATE to bottom Language: C#
Description: This code moves the viewstate to the bottom of the page to remove the spacing at the top it generates. Views: 155
Author: David Ashworth Date Added: 10/9/2007
Copy Code  
1protected override void Render(HtmlTextWriter writer)
2        {
3            StringWriter sw = new StringWriter();
4            HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
5            base.Render(htmlWriter);
6
7            string html = sw.ToString();
8            int StartPoint = html.IndexOf("<div>\r\n<input type=\"hidden\" name=\"__VIEWSTATE\"");
9            if (StartPoint >= 0)
10            {
11                int EndPoint = html.IndexOf("/>\r\n</div>", StartPoint) +10;
12                string ViewStateInput = html.Substring(StartPoint, EndPoint - StartPoint);
13                html = html.Remove(StartPoint, EndPoint - StartPoint);
14                int FormEndStart = html.IndexOf("</form>") - 1;
15                if (FormEndStart >= 0)
16                {
17                    html = html.Insert(FormEndStart, ViewStateInput);
18                }
19            }
20
21            writer.Write(html);
22        }
Usage
Used in a page or Master page to overload the Render Event