Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > button click problem

Reply
Thread Tools

button click problem

 
 
laziers@gmail.com
Guest
Posts: n/a
 
      02-09-2008
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



 
Reply With Quote
 
 
 
 
Ian Semmel
Guest
Posts: n/a
 
      02-09-2008


"(E-Mail Removed)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed):

> 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


 
Reply With Quote
 
 
 
 
Mr. R
Guest
Posts: n/a
 
      02-09-2008
>> 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

>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-10-2008
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


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      02-10-2008
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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-Du...2638096&sr=8-4

and work through it from beginning to end...


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

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      02-10-2008
"Mr. R" <(E-Mail Removed)> wrote in message
news:Cporj.3669$(E-Mail Removed)...

> 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

 
Reply With Quote
 
Ian Semmel
Guest
Posts: n/a
 
      02-10-2008
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.

"(E-Mail Removed)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed):

> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fire both event button click and textchanged when button is click and text is changed Amy ASP .Net 0 06-01-2006 02:33 PM
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Datagrid Control 0 05-25-2004 01:45 AM



Advertisments