2012年3月26日月曜日

Response.Write with update panel issue

I am having a problem with a response.write in page.load and an atlas update panel. I created a quick sample to repro this issue. What should happen is the ddl loads with the current date. If I run it doing a response.write of the stylesheet in the page.load, it does not work. If I put the stylesheet reference at the top of the webform, it works. The page source rendered in IE is exactly the same, however using fiddler I noticed that the Atlas request on the button click returned different results. The main difference is the response.write way returns what I had in the response.write before the delta tags in the fiddler response.

In my codebehind I have:

PartialClass LiveTestInherits System.Web.UI.PageProtected Sub btnClickMe_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles btnClickMe.Click ddlStuff.Items.Add(New ListItem(Date.Now.ToString))End Sub Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load Response.Write("<head><link rel=""stylesheet"" type=""text/css"" href="http://links.10026.com/?link="/tools/style0.css""/></head>")End SubEnd Class
Webform
 
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" CodeFile="LiveTest.aspx.vb" Inherits="LiveTest" %><!--head><link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=/tools/style0.css"/></head--><head runat="server"> <title>Untitled Page</title></head><atlas:ScriptManager ID="sm" runat="server" EnablePartialRendering="true"></atlas:ScriptManager><body> <form id="form1" runat="server"> <div> <div class="Heading">This is a test</div> <asp:Button ID="btnClickMe" Text="Click Me" runat="server" /> <br /> <atlas:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DropDownList ID="ddlStuff" runat="server"></asp:DropDownList> </ContentTemplate> <Triggers> <atlas:ControlEventTrigger ControlID="btnClickMe" EventName="Click" /> </Triggers> </atlas:UpdatePanel> </div> </form></body>
Fiddler Views
(Response.Write Does not work)
<head><link rel="stylesheet" type="text/css" href="/tools/style0.css"/></head><delta><rendering><head><title>....</delta>vs.(Declare stylesheet in html works)
<delta><rendering><head><title>Untitled Page</title><style type="text/css">....</delta>

Is there any kind of workaround for this issue (besides don't response.write your stylesheets)? We dynamically write out different stylesheets based on user preferences in a base page that other web pages inherit from.

Thanks in advance

I found that using

Me.Controls.AddAt(0,New System.Web.UI.LiteralControl("<head>....<style>.....</head>"))

Works fine instead of doing the response.write

Thanks

0 件のコメント:

コメントを投稿