button click problem

L

laziers

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
 
I

Ian Semmel

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.
 
M

Mr. R

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 ?????
 
M

Mark Rae [MVP]

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...
 
M

Mark Rae [MVP]

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...?
 
I

Ian Semmel

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top