DCSIMG
April 2008 - Posts - Just code - Tamir Khason

April 2008 - Posts

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/how-to-have-more-then-one-forms-in-page-and-be-able-to-submit-it-to-server-without-page-refresh-using-aspnet-ajax/]


Someone asked me in Meet an Expert lunch in TechEd about having more, then one server forms in one page, using ASP.NET AJAX. The answer was simple – make only one visible at one time. Other words, hide all and show only one relevant

<script runat=server language="C#">
private void Page_Load(object sender, System.EventArgs e)
 {
  Form1.Visible = !Form1.Visible;
  Form2.Visible = !Form2.Visible;			
 }	

<form id="Form1" runat="server" >…
<form id="Form2" runat="server" visible="false">…

That’s all. However, what to do if you need to show them all? Let’s try to understand. First of all, let’s make them client based

<form id="form1" >…
<form id="form2" >…

Then we should handle onsubmit method and neutralize it, before the page will be reloaded (we do not want reloads – AJAX rulez!)

<form id="form1" onsubmit="onSubmit(this); return false;">…
<form id="form1" onsubmit="onSubmit(this); return false;">…

So, the final code will looks as following (there are some of such forms):

<form id="form1" onsubmit="onSubmit(this); return false;">
    <div>
    <h2>Client Form 1</h2>
    <input type="text" id="val" />
    <input type="submit" value="Submit 1" />
    </div>
    </form>

Then, let’s have one server side form, that will handle our requests

<form runat="server">
<asp:Label ID="Result" runat="server"/>

And now, let’s submit our results there. Yes, we can access server side controls from client side JavaScript

<script type="text/javascript">
       function onSubmit(sender)
       {
            var what = sender["val"].value;
            if(what == "")
                what = "nothing";
            $get("Result").innerHTML=sender.id+" tells you "+what;

       }

Well, but as you, probably understand, there is no real submit was performed. We need client-server-client roundtrip in order to do it. What to do? The answer is PageMethods.

Let’s add simple page method, that formats the string and added time tag

<script runat="server">
            [System.Web.Services.WebMethod]
            public static string UpdatePanel(string senderID, string what)
            {
                return string.Format("{0} tells you {1} at {2} with server roundtrip", senderID, what, DateTime.Now);
            }
       </script>

One we have such. All we have to do is to enable page methods by using ScriptManager

<form runat="server">
    <h2>Result</h2>
        <asp:ScriptManager runat="server" EnablePageMethods="true" />
        <asp:Label ID="Result" runat="server"/>
    </form>

And then, call it from javascript

function onServerSubmit(sender)
       {
            var what = sender["val"].value;
            if(what == "")
                what = "nothing";
            PageMethods.UpdatePanel(sender.id,what,onServerSubmitCompleted);

       }
function onServerSubmitCompleted(value)
       {
         $get("Result").innerHTML=value;
       }

We done. BTW, if we’ll try to pass HTML object into server, we’ll get "Cannot serialize object with cyclic reference within child properties" exception – this is not bug, this is warlock for bad HTML programmers. If you want to be able to pass whole form (HTML object) into server you’ll probably have to either use LosFormatter, or any other custom HTML serializer to do it.  Want to know more about it? Maybe another time.

Have a nice week and be good people.

Source code for this article

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/teched-behind-the-scene-%e2%80%93-system-setup/]


Alex posted his video about how we setup the most complicated demonstration in this TechEd. Now it’s time (I promised) to post my video about how it was at 6 AM after night party in TechEd.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/teched-is-over-%e2%80%93-last-teched-related-post/]


I know, that I made you tired of all those TechEd related posts. So this is the last one (I’ll post full presentation and demo sources later), I promise. Unfortunately, I’ll be unable to attend bloggers’ lunch (my flight is at 8:20 pm), so I want to tell thank to all bloggers, that rapidly posted TechEd related stuff, to all those who worked hard to prepare such event, to all presenters and visitors (do not forget to fill the survey). The event was good. I’d give it 9 of 10. The point missing point for some, who worked not hard enough to prepare and lectures’ start and end punctuality of some presenters. Overall experience was great. You did it! Thank you and see you on next event.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/my-session-is-over-%e2%80%93-great-thanks-to-all-who-was-there/]


I want to tell big thanks to all, who come to see us this morning after the party yesterday. I hope, you was satisfied within the session. Thank you very much! If you have questions – feel free to ask (you can leave comments too).

dontae_5

Great thanks to Alex too. Wait for us to upload two videos of how we prepared this session – stay tuned :)

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/after-party-getting-ready-for-the-presentation/]


Currently it’s 7:40 and we’re getting ready for presentation from 6:30. It’s four laptops, one mobile phone and XBOX. All this stuff should work. Be sure to attend today @10:45, Hilton, Knaan – Game development

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/teched-eilat-08-%e2%80%93-it%e2%80%99s-turns-better/]


Referring my last post. TechEd turns to be better for me. It seemed, like I simple choose wrong sessions. Last one I attended was really great 9-9. It returns me to the original idea, that I have really serious competitors for my session :) See you there tomorrow 10:45@Hilton.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/maxim-alexandrovich-%e2%80%93-i%e2%80%99m-waiting-for-you/]


I’m currently in meeting area of conference center waiting for Maxim Alexandrovich. We set an appointment to 10:00 today. There are technical problems with meeting systems, so I cannot get your phone number. So, I you’re here, please come. I’m waiting for you.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/teched-eilat-%e2%80%93-day-two-%e2%80%93-i-disappointed/]


TechEd, Eilat, Day two and I’m very disappointed of what’s going on here. I cannot give more, then five of ten to any session I attended. I DISAPPOINTED! I do not want to tell the names of those sessions, however it looks like nether of presenters worked too hard to prepare it. I DISAPPOINTED. I worked more then two weeks to prepare my presentation (incl. repetitions, rewriting, fixing and touching), I have to work two hours more to prepare it finally and I do not know today why I did and will do it. I DISAPPOINTED.

The other huge problem, that neither of sessions stared and finished in time and there are voices in coridors about leaving TechEd today… I DISAPPOINTED DEEPLY DISAPPOINTED.

200488557-001

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/teched-day-1-%e2%80%93-keynotes-%e2%80%93-nice-presentation-in-spite-of-some-bugs/]


I’m in Eilat, in TechEd event. First impression – very good arrangements. Upon by arrival, the room was ready and it was big and clean. First I couch by some of partners and friends. Then, I was in bloggers meeting, where received some  nice toys to play with. Now, let’s speak about first significant event – the keynotes. Yochai was good, in spite of some technical problem. However, the most problematic one was the fact, that he completely forgot about our promo. Actually, I understand him – 3.5 hours. Second thing in his presentation was IIS7. I have some problem with this stuff. One of them is how it works on Windows Vista (see the live image about how real TechEd Vista looks like)

Real vista from TechEd

Now to our presentation. Actually, after more then 3 days of working to make IIS on Vista work fluently, I was very disappointed and thus, just recompile IIS asapi filter for Apache on Linux. Do not believe me? Come to see it live.

So by now, I’m going to business center to sit with some partners. If you want to, you’re welcome to catch me there for next hour. See ya and wait for upcoming updates.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/teched-is-over-the-corner-and-we-are-ready-what-about-you/]


After a lot of work I’m ready for TechEd. It worth me a lot of blood, sweat and tears until it started to work as I expected. What our session about? In one sentence – Game Development. In number of sentences – we’ll build online car racing multiplayer game, that will run on XBOX, Windows, Linux, Mac and mobile phone. All this will be tied up with Windows Live services. During the session, XBOX will play with WPF and Novel Suse Linux will run ASP.NET and play with IIS7. Don’t believe me? Come and see. Here small video, that demonstrates some of this session results. There are much more to see…

See you there 8th of april, 10:45 in Knaan hall of Hilton hotel in Eilat.

More Posts « Previous page