button click problem

Discussion in 'ASP .Net' started by laziers@gmail.com, Feb 9, 2008.

  1. Guest

    Hi,

    I have a code like this:

    protected void Page_Load(object sender, EventArgs e)
    {
    // CODE1
    }

    protected void Button_Click(object sender, EventArgs e)
    {
    // CODE2
    }

    I was noticed that when I click the button, CODE1 executea and after
    that CODE2 executes.
    Here is the problem, I dont want to execute CODE1 but only CODE2 [and
    I dont want to use isPostBack].
    Is there anyway to do this? I thik that the best way is getting name
    or id of the clicked button.

    bye
     
    , Feb 9, 2008
    #1
    1. Advertising

  2. Ian Semmel Guest

    "" <> wrote in message
    news::

    > Hi,
    >
    > I have a code like this:
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > // CODE1
    > }
    >
    > protected void Button_Click(object sender, EventArgs e)
    > {
    > // CODE2
    > }
    >
    > I was noticed that when I click the button, CODE1 executea and after
    > that CODE2 executes.
    > Here is the problem, I dont want to execute CODE1 but only CODE2 [and
    > I dont want to use isPostBack].


    But that's the way it works. In Page_Load, you use IsPostBack to
    determine why you are there - is the page being loaded or did someone
    click the button.

    > Is there anyway to do this? I thik that the best way is getting name
    > or id of the clicked button.
    >
    > bye
     
    Ian Semmel, Feb 9, 2008
    #2
    1. Advertising

  3. Mr. R Guest

    >> Hi,
    >>
    >> I have a code like this:
    >>
    >> protected void Page_Load(object sender, EventArgs e)
    >> {
    >> // CODE1
    >> }
    >>
    >> protected void Button_Click(object sender, EventArgs e)
    >> {
    >> // CODE2
    >> }
    >>
    >> I was noticed that when I click the button, CODE1 executea and after
    >> that CODE2 executes.
    >> Here is the problem, I dont want to execute CODE1 but only CODE2 [and
    >> I dont want to use isPostBack].


    A comment from a nowbie in ASP.NET. As I understant you have to deffer
    ASP.NET programming from ordinary programming. ASP.NET is created for
    homepages and in the end generating HTML and Javascripts for the browser.
    Compare it with an botton that opens a new URL but that it opens the new
    page with a prameter sayng that the page is reloaded.

    Can some one tell me if I assume right or not.

    Every time you change a pages HTML text, by ASP.NET, Java or by PHP the page
    is reloaded, that is, sent back from the server. Can you really change a
    pages code without reloading it from the server. Sure JAva code can change
    the apperance but to change the actual Java or HTML code don't you have to
    reload the page from the server. Which of course would be done automaticly.

    Lars ?????


    >
    > But that's the way it works. In Page_Load, you use IsPostBack to determine
    > why you are there - is the page being loaded or did someone click the
    > button.
    >
    >> Is there anyway to do this? I thik that the best way is getting name
    >> or id of the clicked button.
    >>
    >> bye

    >
     
    Mr. R, Feb 9, 2008
    #3
  4. Peter Bromberg has an article that may help you:

    ASP.NET: Which Control Posted Back?
    http://www.eggheadcafe.com/articles/20050609.asp

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    <> wrote in message
    news:...
    > Hi,
    >
    > I have a code like this:
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > // CODE1
    > }
    >
    > protected void Button_Click(object sender, EventArgs e)
    > {
    > // CODE2
    > }
    >
    > I was noticed that when I click the button, CODE1 executea and after
    > that CODE2 executes.
    > Here is the problem, I dont want to execute CODE1 but only CODE2 [and
    > I dont want to use isPostBack].
    > Is there anyway to do this? I thik that the best way is getting name
    > or id of the clicked button.
    >
    > bye
    >
    >
    >
     
    Eliyahu Goldin, Feb 10, 2008
    #4
  5. <> wrote in message
    news:...

    > I noticed that when I click the button, CODE1 executes and after
    > that CODE2 executes.


    That's correct - that's exactly how it's supposed to work...

    > Here is the problem, I dont want to execute CODE1 but only CODE2 [and
    > I dont want to use isPostBack].


    ??? Why on earth don't you want to use IsPostback...??? It's designed
    precisely for this...

    > I thik that the best way is getting name or id of the clicked button.


    That is *entirely* the wrong approach... ASP.NET, like all of .NET, is
    object-orientated, not linear...

    There are ways to find out the name of the object which initiated the
    postback, but there is no real need to know this...

    Basically, the Page_xxx methods fire every time a page loads regardless of
    how it loads. You use the IsPostback check to determine when the code runs
    in these methods.

    I suggest you get a copy of this:
    http://www.amazon.com/ASP-NET-3-5-D...bs_sr_4?ie=UTF8&s=books&qid=1202638096&sr=8-4

    and work through it from beginning to end...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Feb 10, 2008
    #5
  6. "Mr. R" <> wrote in message
    news:Cporj.3669$...

    > ASP.NET is created for homepages


    Er, you can use ASP.NET for *all* of the pages within web sites and web
    applications, not just the home page...

    > Can you really change a page's code without reloading it from the server?
    > Sure Java code can change the apperance


    Do you mean JavaScript...?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Feb 10, 2008
    #6
  7. Ian Semmel Guest

    Programming for the web requires a paradigm-shift compared to
    programming for windows.

    I suggest you go back to basics to get an overview as to what is
    happening.

    Perhaps if you go to Help and look for 'ASP.NET Page Life Cycle
    Overview' and follow it through, you will get the idea.

    "" <> wrote in message
    news::

    > Hi,
    >
    > I have a code like this:
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > // CODE1
    > }
    >
    > protected void Button_Click(object sender, EventArgs e)
    > {
    > // CODE2
    > }
    >
    > I was noticed that when I click the button, CODE1 executea and after
    > that CODE2 executes.
    > Here is the problem, I dont want to execute CODE1 but only CODE2 [and
    > I dont want to use isPostBack].
    > Is there anyway to do this? I thik that the best way is getting name
    > or id of the clicked button.
    >
    > bye
     
    Ian Semmel, Feb 10, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    864
    Purvi T
    Oct 19, 2004
  2. mike parr
    Replies:
    1
    Views:
    480
    Marina
    May 20, 2004
  3. Ben Fidge
    Replies:
    5
    Views:
    740
    S. Justin Gengo
    Jun 15, 2004
  4. Amy
    Replies:
    0
    Views:
    997
  5. Tim
    Replies:
    0
    Views:
    427
Loading...

Share This Page