Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancel Postback on button click

Status
Not open for further replies.

hsviljoen

Programmer
May 26, 2004
73
ZA
I hope this is possible.... does nayone know how i can cancel / dissable the postback of a form on a button_click event????

Thanks for your time!...
 
dunno about disabling the postback but you can use if me.ispostback = false to get around it.
 
Under what circumstances do you want to cancel the postback?

Rhys

"Vampireware /n/,a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

"I see dead pixels!
 
OK - here is the sittuation - Im developing a online Chat app - I wanted the on click event of the send button not to reload the page .... I guess this would be very easy in ASP.NET 2.0 as they've implemented client_side events. The other thing has well , i want to update the 'ChatArea' textbox without a refresh , will this be possible?
 
You can use Client Callbacks to refresh certain parts of the page without posting back the whole page. For more info see:


--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
I can't remember the axact syntax but you can do something like OnClick="return JavaScript:someFunction();" as an attribute of the button control. Then in your javascript function do something like the following:

<script language='JavaScript'>

function someFunction()
{
if(some dondition here == true)
{
return true;
}
else
{
return false;
}
}
</script>

Returning false will prevent the postback from occurring.

HTH
 
Guys, thank you for all your comments - but i think I need to explain the exact sittuation:

OK I receive a string with the new chat message from a timer, I then need to update the textbox.... I tried using javascript ... Using Page.RegisterStartupScript and a view others - the problem seem to be that the functio does not get called if my code runs from a sub / function - What I mean is , if a call the function from a button_click sub it works... Even tried using button_click(nothing,nothing)...

Ok , second problem ,
I want to call a asp function which basicly sends a message and add thext to my textbox - Here i want to do all this without "REFRESHING" the page ...


I really appreciate all the efford , Thanks
 
Your second problem can be done with the link I provided above? Did you check it out?

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
So, your problem number one is that you want your your application to post to a remote server on a timed basis, check for new 'chat' text to display and display it in the text box of your application, without the displayed page in it's entirety posting to the host server and refreshing?

Rhys

"Vampireware /n/,a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

"I see dead pixels!
 
:~( Lets start with the biggest issue:

upon a event - I want to update a textbox and show the new text without refreshing the page... eg:

timer_elapsed(.....)
if xmsg.length > nmsg.length then
txtChatArea.Text = nmsg
End if
 
So if you combine a timer with the methodology provided in that very handy link by ca8msm you should be able to work out about posting page elements rather than the entire page which is what you want, however I feel it unlikely that you can update a control on the client from the server without refreshing at least the control you want to update.

Honestly, I think you need to look closely at ca8msm's link and make an assessment of whether what you want to do is realistically acheivable in .Net 1.1.

Also, try having a look at this...
Code Project Article


Rhys

"Vampireware /n/,a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

"I see dead pixels!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top