in

ASP.NET Weblogs

Natty Gur

.Net from enterprise architect point of view.

May 2004 - Posts

  • Step by step guide for developing custom server control with custom collection editor

    This guide is step by step instruction to create custom web control. The describe control contains complex property (Collection of classes) that the user can edit using custom type editor. Collection data will be preserving by control as control sub Html tags. This guide also contains most common issues relating to development such a control. The control that we about to develop name is commands and it part of NWAF framework that I'm working on. This control task is to let users to set commands to server control events laid down on web page. Commands has a property holding collection of classes that containing control name, event name and command name set to specify event. The user can add command to control events by using custom editor. Our custom editor show controls on page in hierarchal view. Choosing a control show it server side events and while selecting given event the user can set command name for that event. Controls event commands persist as inner HTML under commands control tags. The HTML output of our control should look like:

    <cc1:Commands id="Commands2" style="Z-INDEX: 105; LEFT: 24px; POSITION: absolute; TOP: 107px" runat="server" Height="2px" Width="15px">
        <cc1:InnerCommand EventName="Click" ControlID="Button1" CommandName="a"></cc1:InnerCommand>
        <cc1:InnerCommand EventName="Command" ControlID="Button1" CommandName="b"></cc1:InnerCommand>
        <cc1:InnerCommand EventName="SelectedIndexChanged" ControlID="DropDownList1" CommandName="natty"></cc1:InnerCommand>
        <cc1:InnerCommand EventName="TextChanged" ControlID="TextBox1" CommandName="roni"></cc1:InnerCommand>
    </cc1:Commands>

    Full article : http://weblogs.asp.net/ngur/articles/144770.aspx

    Complete code available for download.

  • Another cause to "Error while trying to run project: unable to start debugging on the server" for ASP.NET application.

    I found out today that if IE security (Tools-> Internet options-> Security -> Internet or Intranet -> Custom level -> User authentication) is set to anonymous logon, you will get the above error. I didn’t find any mention for this cause so here it is.

  • Looking for new job offers

    I'm about to finish my existing contract and I'm looking for new one. Currently I'm in Israel but I consider relocation to USA (west coast preferred but not a must). Yes, I need visa sponsorship and all that … But I'm positive sure that I can contribute a lot J

     

    So if some one looking for .Net guy, with vast experience with .Net in large enterprises, I'll be happy to hear …

  • Loading dynamic user controls from Page_Load cause ViewState problems.

    I've seen couple of post on that issue lately so I decide to comment on that Issue. ViewState holds controls state as they where before server side processing of page finished. Controls state is saved by SavePageStateToPersistenceMedium to hidden field and retrieves from hidden field by LoadPageStateFromPersistenceMedium.

    As I post in my article about ViewState viewer (http://www.codeproject.com/aspnet/viewstate_viewer.asp) viewstste is order by the controls position in controls collection of HtmlForm object. If controls add to HtmlForm after LoadPageStateFromPersistenceMedium load controls viewstate there isn't any correlation between controls order and viewstate order and … you probably got a problem.

    If you will follow events order on page you will see that Page_Load (event) happened after LoadPageStateFromPersistenceMedium. Page init happen just before LoadPageStateFromPersistenceMedium. So moving your code (that loads user control) from Page Load event to Page init event will cause control tree to be finish before ViewState load and viewstate behave as expected.

  • PreRender event not firing on ImageButton

    Well there is a bug in ImageButton OnPreRender that simply don’t call base.OnPreRender so your event handler will never run. If you want to workaround this problem you can create your own ImageButton. Your new web custom control should overload OnPreRender and PreRender event.

     

    The following code demonstrates ImageButton control that will raise PreRender event:

     

    public class MyImageButton : ImageButton 

          {

                public new event EventHandler PreRender;

                public MyImageButton() : base()

                {

                     

                }

                protected override void OnPreRender(EventArgs e)

                {

                      if (PreRender != null)

                          PreRender(this,e);

                      base.OnPreRender(e);

                }

     

               

          }

    }

     

  • Smart clients and CGI Timeout

    If you get this error while downloading smart client application to browser client:

     

    " CGI Timeout
    The specified CGI application exceeded the allowed time for processing. The
    server has deleted the process. "

     

    Check if your virtual directory executes permission set to "script and executables". If so the server tries to run smart client exe instead of returning it as byte stream. Change your virtual directory execute permission to Script only.

     

  • Send data from non browser client (using HttpWebRequest) that can be used by access web page controls.

     If you use HttpWebRequest to send request via Form, that contain server side controls names and values, to the server you except server control to hold the values that send from the client. Exactly as you send data using browser to the server. The following code should send data to Textbox1 and TextBox2 and if I set a bookmark inside page load I should access the textboxes value using textbox text property

    <CODE>

        Sub Main()

            Dim URL As String = "http://localhost/webapplication36/webform1.aspx?"

            Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(URL), HttpWebRequest)

            myHttpWebRequest.Method = "POST"

            Dim postData As String = "TextBox1=myusername&TextBox2=mypassword"

            Dim encodedData As New System.Text.UTF8Encoding

            Dim byteArray As Byte() = encodedData.GetBytes(postData)

            myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"

            Dim cont As CookieContainer = New CookieContainer

            'myHttpWebRequest.CookieContainer = New CookieContainer

            'myHttpWebRequest.CookieContainer.Add(cont.GetCookies(New System.Uri(URL)))

          

            myHttpWebRequest.ContentLength = byteArray.Length

            Dim newStream As Stream = myHttpWebRequest.GetRequestStream()

            newStream.Write(byteArray, 0, byteArray.Length)

            newStream.Close()

            myHttpWebRequest.AllowAutoRedirect = True

            Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

            'read response

             . . .

    }

    </CODE>

    The problem is that this code won't cause TextBox1 and TextBox2 to hold the submitted form data.

    The webform won't add the submitted values to controls because the form is missing __VIEWSTATE hidden form field. From the page point of view request that arrive to the server without __VIEWSTATE field are first time request to given page. While page call for the first time there isn’t any values to preserve, on the contrary one of the page tasks is to save controls state into __VIEWSTATE field. From the page point of view if __VIEWSTATE field isn’t exist ASP.NET won't load controls and set their values.

    So the trivial solution is to add "&__VIEWSTATE=" to the form data submitted from the client. The problem is that adding this data will cause your web to return error to the client with error description saying that the ViewState data is corrupted.

    <CODE>

    Dim postData As String = "TextBox1=myusername&TextBox2=mypassword&Button1=Button&__VIEWSTATE="

    Dim encodedData As New System.Text.UTF8Encoding

    Dim byteArray As Byte() = encodedData.GetBytes(postData)

    </CODE>

    Actually the problem is within page LoadPageStateFromPersistenceMedium method which responsible to load view state from __ViewState field. The Request holds indication that ViewState data sent so the page. The page tries to persist data from __ViewState field but __ViewState field hold nothing or garbage.

    To fix this problem you can overload LoadPageStateFromPersistenceMedium in such a way that if the __ViewState field holds corrupted data (or empty data, you can check the Form value)  the page life cycle will continue. This way given page can serve browser and HttpWebRequest requests :

    <CODE>

    protected override object LoadPageStateFromPersistenceMedium()

    {

          object oViewState = null;

          try

          {

                /*

                // can check __VIEWSTATE –

                if(Request.Form["__VIEWSTATE"] != "")

                      return base.LoadPageStateFromPersistenceMedium();

                */         

                oViewState = base.LoadPageStateFromPersistenceMedium();

               

          }

          catch(Exception HttpException)

          {

               

          }

          return oViewState;

    }

    </CODE>

  • Releasing Oracle connections from .Net application.

    I've got many replies to that post. So I decide to try making it clearer.

    If you see that Oracle holds Connections of your application with invalid status check:

     

    1)      That you are using Oracle ODP.NET provider (version 102 or higher) and not Microsoft provider for oracle. This bug solved just in ODP.NET.

    2)      Ensure that you close all your open connections by closing or disposing OracleConnection.

    3)       Pay attention to those two connection string options: "Decr pool size" and "Incr pool size". "Decr pool size" set the Number of connections that are closed when an excessive amount of established connections are unused. "Decr pool size" default value is 1. ". "Incr pool size" set the Number of connections established when all connections in pool are used. "Incr pool size"  defult value is 5. As you can see those default values can cause the pool to reach it maximum connection pool size default value (Default - 100).

    4)      Any other suggestion …

     

  • Microsoft and the enterprise market, is it reality?, MS response.

    Richard Turner (Program Manager, XML Enterprise Services) response to my critique.

    It's a long thread and his replay is one befor the last post.

    http://channel9.msdn.com/ShowPost.aspx?PostID=4449

  • Naked objects and competitive intelligence

    I already post about naked objects. I really found the idea of letting users controlling the flow between objects instead of predefined application flows predefined by analysts and programmers. As I thought about naked objects and talked about it with others I found out that naked objects actually "invented" for competitive intelligence (CI) solutions. CI work is about identifying entities in your business environment and relations between those entities. Those entities could be Companies, figures, products, countries, organizations and so on. Finding different relations between entities usually helps analysts to drive into conclusion about "research target" intensions, movements, etc' that might harm or benefit their company. Searching after entities and links is very dynamic process. Usually its hours of reading that pop-up pre-defined as new entity types. The user need to draw "CI picture" that holds all instances of pre-defined entities, pre-defined links as well as new entity types and links which both of them contain new properties and methods. This "CI picture" is complex and dynamic objects graph that should be adjusted any time in the analysis process.

     

    Now let's back to naked objects. If we are going to use it out of the box we can set pre-defined entities and types and the framework will let our user to create instances of those pre-defines entities and relegations between them. He can see entities from different systems (interior and exterior) and their relations on single page as he wants to see them and apply tier methods in the order he wants. If we will adjust the framework a little bit and enable creating of entities and links on the fly, by the user. Now our user can create any object graph that he wants. Upgrading the visual aspect of the framework so link analysis could be show with presentation algorithms and our user can get insights just by looking at presentations.

     

    No doubt that such system that let the user set entities and relations, view them and activate them is any possible order is Killer application for CI market.

     

More Posts Next page »