turn off autopostback and call it explicitly when you need to. problem is,
you cant turn it off for a button, so try an HtmlButton.

On Thu, Dec 4, 2008 at 3:40 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]
> wrote:

>
> Yup, you're right, the output is being rendered before the attack
> method is processed.  Unfortunately, I'm not sure how to fix it.
>
> This is what's happening:
>
> The attack button is clicked, and the page is reloaded due to the post
> back.
> The page is reloaded before the attack is processed, and the output -
> which is written by the page's code behind file during the Page_Load
> event - is displayed.
> The attack is finally processed, but the results aren't seen because
> the page has already been rendered.
>
> Is there a way to force the attack processing to take place before the
> page load?  This is what I currently have:
>
> public partial class _Default : System.Web.UI.Page
> {
>    protected void Page_Load(object sender, EventArgs e)
>    {
>        PlayerCharacter PC = null;
>        PlayerCharacter Enemy = null;
>
>        if (Page.IsPostBack)
>        {
>            PC = (PlayerCharacter)Context.Session["attacker"];
>            Enemy = (PlayerCharacter)Context.Session["target"];
>        }
>        else
>        {
>            PC = new PlayerCharacter("Neo", "Male", "A young hacker,
> unaware that he's the chosen one", new Hacker());
>            Enemy = new PlayerCharacter("Smith", "Male", "An agent of
> the Matrix", new Shill());
>        }
>
>        PC.Money = 2.34f;
>
>        Context.Session["attacker"] = PC;
>        Context.Session["target"] = Enemy;
>
>        AttackEventArgs attackArgs = new AttackEventArgs(Context);
>        List<Attack> PCattacks = PC.Attacks;
>
>        attack.Click += delegate { PCattacks[0].ExecuteAttack(this,
> attackArgs); };
>
>        mainLabel.Text = PC.Name + " ";
>        mainLabel.Text += PC.Gender + "\n<br />";
>        mainLabel.Text += "HP: " + PC.CurrentHP + " TP: " +
> PC.CurrentTP + " DMG: " + PC.DMG + "\n<br />";
>        mainLabel.Text += "Money: $" + PC.Money + "\n<br />";
>        mainLabel.Text += PC.Class.GetType().ToString() + "\n<br /
> ><br />";
>        mainLabel.Text += "Attack info before leveling up: <br />";
>        mainLabel.Text += "DMG: " + PC.DMG + " DMG Modifier " +
> PC.DMGModifier + " Chance to Hit: " + PC.ChanceToHit + "<br /><br />";
>        mainLabel.Text += "Enemy HP: " + Enemy.CurrentHP + "<br /><br /
> >";
>     }
> }
>
> On Dec 4, 3:24 am, CK <[EMAIL PROTECTED]> wrote:
> > it sounds like you may be handling the display of the enemy
> > characteristics (e.g. in Page_Load) before the button event is
> > raised.  Try putting break points on each method and watch what
> > happens.
> >
> > On 3 Dec, 18:13, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > wrote:
> >
> > > Like I've said in other messages, I'm currently attempting to write a
> > > web-based game (RPG).  For my combat system, I'm attempting to create
> > > a turn-based system where the player and computer-controlled character
> > > swap turns.  Every attack a combatant can execute is, itself, an
> > > object.  The actual attack is a method of that object.
> >
> > > Right now, in my test page, I have a simple attack scenario.  I have
> > > one button tied to the player character's base attack.  When clicked,
> > > the attack executes, and the enemy is hit.  My problem is that the
> > > output which displays the hit is delayed by a turn.  In other words, I
> > > click the attack button, and the page reloads, but the enemy shows no
> > > damage, even though the debugger shows that 1. the attack was
> > > successful, and 2. damage was recorded.  In each new battle, no damage
> > > is ever displayed after the first turn, even if it was a success.
> >
> > > I'm saving the two combatants in a session in order to save their
> > > state for the post back.  That way, I can see the damage accrue as I
> > > click the attack button.  Could the session be causing the delay?
> >
> > > Let me know if I need to post my code.  I didn't post it initially
> > > because I didn't want to write a huge message and annoy everyone.
>

Reply via email to