Archive for the 'asp.net' Category

March 27
asp.net ajax, its a hack but it works?
posted by mike at 12:23 pm

so when I started fooling around w/ asp.net ajax... back when it was called atlas... I would talk w/ fellow developers and say "well it seems like a hack, but it works". We even talked about starting an asp.net ajax blog... and calling it that... because atlas felt like a total hack when ever you wanted to do something out of their "hey drop it in an update panel" mantra.

well today I found something that reminded me very much of that feeling.... it kind of goes along w/ the key up issue that came up last week. This time I'm making a custom control, to do essentially what the titles on pageflakesdo, allow some one to click on a section of text, edit it, on blur flip it back to text, and fire an ajax postback.... I had done this a while ago... but guess didnt test it so much... because i just found that if you didnt change the text, but just blured it wouldnt fire the event. Essentially what I found was the "ontextchange" event was doing exactly as described, it would only fire when the control was blured, and changed.

so I hacked this.

C#:
  1. txtEdit.Attributes.Add("onblur","$get('" + txtEdit.ClientID + "').value+=' ';" + this.Page.GetPostBackEventReference(txtEdit));

doh

 
March 26
log4net god bless your debug setting
posted by mike at 2:35 pm

so I was having some problems getting log4net integrated with a site I was working on... for no reason It was not writing to the AdoNetAppender.

This is what I had as the adapter

XML:
  1. <appender name="ADONetAppender" type="log4net.Appender.AdoNetAppender">
  2.         <bufferSize value="1" />
  3.         <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  4.         <connectionString value="SERVER=127.0.0.1\sql;DATABASE=dbname;UID=sa;" />
  5.         <commandText value="INSERT INTO ProcessLogLog4Net (Message,thread,level,logger,exception) VALUES (@message,@thread,@log_level,@logger,@exception);" />
  6.         <parameter>
  7.             <parameterName value="@log_date" />
  8.             <dbType value="DateTime" />
  9.             <layout type="log4net.Layout.RawTimeStampLayout" />
  10.         </parameter>
  11.         <parameter>
  12.             <parameterName value="@thread" />
  13.             <dbType value="String" />
  14.             <size value="255" />
  15.             <layout type="log4net.Layout.PatternLayout">
  16.                 <conversionPattern value="%thread" />
  17.             </layout>
  18.         </parameter>
  19.         <parameter>
  20.             <parameterName value="@log_level" />
  21.             <dbType value="String" />
  22.             <size value="50" />
  23.             <layout type="log4net.Layout.PatternLayout">
  24.                 <conversionPattern value="%level" />
  25.             </layout>
  26.         </parameter>
  27.         <parameter>
  28.             <parameterName value="@logger" />
  29.             <dbType value="String" />
  30.             <size value="255" />
  31.             <layout type="log4net.Layout.PatternLayout">
  32.                 <conversionPattern value="%logger" />
  33.             </layout>
  34.         </parameter>
  35.         <parameter>
  36.             <parameterName value="@message" />
  37.             <dbType value="String" />
  38.             <size value="4000" />
  39.             <layout type="log4net.Layout.PatternLayout">
  40.                 <conversionPattern value="%message" />
  41.             </layout>
  42.         </parameter>
  43.         <parameter>
  44.             <parameterName value="@exception" />
  45.             <dbType value="String" />
  46.             <size value="2000" />
  47.             <layout type="log4net.Layout.ExceptionLayout" />
  48.         </parameter>
  49.         <filter type="log4net.Filter.LevelRangeFilter">
  50.             <acceptOnMatch value="true" />
  51.             <levelMin value="WARNING" />
  52.             <levelMax value="FATAL" />
  53.         </filter>
  54.  
  55.     </appender>

this is what I had when I constructed it in the wrapper object

C#:
  1. private static log4net.ILog Log
  2.         {
  3.             get
  4.             {
  5.                 if (_log == null)
  6.                 {
  7.                     log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Log4NetConfigFile));
  8.                     _log = log4net.LogManager.GetLogger(HttpContext.Current.Server.MachineName);
  9.                 }
  10.  
  11.                 return _log;
  12.             }
  13.         }

it worked just fine for the rolling adapter... I was stumped. Then I found this little nugget in the faq

XML:
  1. <add key="log4net.Internal.Debug" value="true"/>

at the end of the day, for one reason or another log4net couldn't resolve the domain of the sql box... If it werent for the debug pumping an error out to the console I would never have seen this and just keep hitting my head on the desk. good times

 
March 21
asp.net ajax postback on keyup
posted by mike at 9:30 pm

so I got a question from some one via the cmap group, for some help with a kind of tricky asp.net ajax problem. So they had been using a pagemethod, to retrieve a list from a web service to update a datalist. Sounds simple enough... but the problem w/ using web services from client code in asp.net ajax is that the page method, which although it exists in the codebehind of a page, and used to be accessable from the instance of the page in atlas, now has to be static... anywho.... so the problem is if you call a webservice in client js, its hard to do things like bind a datalist...

so my solution/kludge was to add the postback js call of a control, to the onkeyup js event of the textbox. Basicly forcing the textbox to do a asp.net postback on a keyup (really this should be only posted back like every 3 key ups...)

heres the aspx

CODE:
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="onkeyuppostback.aspx.cs" Inherits="onkeyuppostback" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7.     <title>Untitled Page</title>
  8. </head>
  9. <body>
  10.     <form id="form1" runat="server">
  11.     <div>
  12.     <asp:ScriptManager runat="server" ID="smTest" EnablePartialRendering="true"></asp:ScriptManager>
  13.         <asp:TextBox runat="server" ID="txtTest" AutoPostBack="True" OnTextChanged="txtTest_TextChanged"></asp:TextBox>
  14.     <asp:UpdatePanel runat="server" ID="upTest">
  15.         <ContentTemplate>
  16.             &nbsp;
  17.         <asp:DataList runat="server" ID="dlTest" Width="207px">
  18.             <ItemTemplate>
  19.                 <%# Container.DataItem %>
  20.             </ItemTemplate>
  21.         </asp:DataList>     
  22.         </ContentTemplate>
  23.         <Triggers>
  24.             <asp:AsyncPostBackTrigger ControlID="txtTest" />
  25.         </Triggers>
  26.     </asp:UpdatePanel>
  27.     </div>
  28.     </form>
  29. </body>
  30. </html>

and here is the cs

C#:
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. public partial class onkeyuppostback : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.        txtTest.Attributes.Add("onkeyup", this.GetPostBackClientEvent(this.txtTest,string.Empty));
  17.     }
  18.  
  19.     protected void txtTest_TextChanged(object sender, EventArgs e)
  20.     {
  21.         dlTest.DataSource = System.DateTime.Now.ToString();
  22.         dlTest.DataBind();
  23.     }
  24. }

so yah kind of kludgy, but is an option in general for doing something in js, which will force a asp.net ajax updatepanel postback... for example, add a button somewhere, have it w/ a style display:none;, then on serverside create a js function that calls its postback function.