Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

button click problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
laziers@gmail.com - 09 Feb 2008 17:01 GMT
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 - 09 Feb 2008 17:42 GMT
> Hi,
>
[quoted text clipped - 14 lines]
> 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
Mr. R - 09 Feb 2008 20:53 GMT
>> Hi,
>>
[quoted text clipped - 14 lines]
>> 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
[quoted text clipped - 4 lines]
>>
>> bye
Mark Rae [MVP] - 10 Feb 2008 10:12 GMT
> 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...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Eliyahu Goldin - 10 Feb 2008 09:40 GMT
Peter Bromberg has an article that may help you:

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

Signature

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

> Hi,
>
[quoted text clipped - 18 lines]
>
> bye
Mark Rae [MVP] - 10 Feb 2008 10:09 GMT
> 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-Dummies-Computer-Tech/dp/0470195924/ref=pd_bbs
_sr_4?ie=UTF8&s=books&qid=1202638096&sr=8-4


and work through it from beginning to end...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Ian Semmel - 10 Feb 2008 19:26 GMT
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.

> Hi,
>
[quoted text clipped - 18 lines]
>
> bye

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.