469,648 Members | 1,564 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,648 developers. It's quick & easy.

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

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.

Jan 31 '07 #1
3 1027
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" <sp**********@yahoo.co.ukwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
>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.

Jan 31 '07 #2
"Greg" <sp**********@yahoo.co.ukwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
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.
Jan 31 '07 #3
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.

Jan 31 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Kenneth | last post: by
2 posts views Thread by Ralph Krausse | last post: by
2 posts views Thread by Islamegy® | last post: by
3 posts views Thread by Neven Klofutar | last post: by
3 posts views Thread by gaDev | last post: by
3 posts views Thread by vtxr1300 | last post: by
8 posts views Thread by rahulnag22 | last post: by
1 post views Thread by Geoffrey | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.