PC Review


Reply
Thread Tools Rate Thread

Change of state in reponse to the click event of a button.

 
 
Greg
Guest
Posts: n/a
 
      31st Jan 2007
I have a button on my form that I am using to allow the user to
validate the contents of a certain textbox.
Depending on the results of the validation, I need to change the
backcolour of the text box and make a call to the database, and
populate several controls with the result from this call to the
database.
However, since the click event is fired too late in the page cycle, it
is too late for the changes made to the controls to actually appear on
the form - these changes will only appear the next time a postback
occurs.

What is the best solution to this? Force another postback once I have
received data from the database, or to do some Javascript work to
change the values from the client side ( I assume this is possible,
but correct me if I'm wrong!).

Regards,

Greg.

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      31st Jan 2007
Greg,

Apparently you are setting up the controls in Page_Load event. You need
someone to tell you that the button was clicked. One of the ways is to
introduce a hidden input element and set it on client side when the button
is clicked. You can access the hidden field in the Page_Load.

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


"Greg" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a button on my form that I am using to allow the user to
> validate the contents of a certain textbox.
> Depending on the results of the validation, I need to change the
> backcolour of the text box and make a call to the database, and
> populate several controls with the result from this call to the
> database.
> However, since the click event is fired too late in the page cycle, it
> is too late for the changes made to the controls to actually appear on
> the form - these changes will only appear the next time a postback
> occurs.
>
> What is the best solution to this? Force another postback once I have
> received data from the database, or to do some Javascript work to
> change the values from the client side ( I assume this is possible,
> but correct me if I'm wrong!).
>
> Regards,
>
> Greg.
>



 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      31st Jan 2007
"Greg" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> Force another postback once I have received data from the database,


Generally speaking, the fewer roundtrips to the server and back that your
app needs to do, the better it will perform...

> or to do some Javascript work to change the values from the client side
> ( I assume this is possible, but correct me if I'm wrong!).


Almost certainly.

<script type="text/javascript">
function validateForm()
{
if(...some client-side test fails...)
{
return false;
}
}
</script>


<asp:Button ID="MyButton" OnClick="MyButton_Click" OnClientClick="return
validateForm();" Text="Test" />

When the user clicks MyButton, it will run the JavaScript function. If the
JavaScript functions returns false, the button will not proceed with the
postback.


 
Reply With Quote
 
Greg
Guest
Posts: n/a
 
      31st Jan 2007
Thanks Eliyahu and Mark,

That worked a treat! This has been annoying me for a long time, I'm so
pleased I got it sorted!

Greg.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Change button on click event =?Utf-8?B?R3JlZyBTbmlkb3c=?= Microsoft Access Form Coding 2 31st Jan 2007 05:47 PM
How to fire both event button click and textchanged when button is click and text is changed Amy Microsoft ASP .NET 0 1st Jun 2006 03:33 PM
change of session does not fire button click event for second time =?Utf-8?B?Ti4gU2hlaHphZA==?= Microsoft ASP .NET 3 5th Apr 2005 09:06 PM
change of session does not fire button click event for second time =?Utf-8?B?Ti4gU2hlaHphZA==?= Microsoft Dot NET 0 4th Apr 2005 06:17 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge Microsoft ASP .NET 2 26th May 2004 12:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 AM.