Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to reload the page in OnClick method?
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
ASP.NET
Miscellaneous
Thread ID:
01169184
Message ID:
01169669
Views:
7
This message has been marked as a message which has helped to the initial question of the thread.
>>>What is the command to put into the OnClick method of a button that will reload the page but not post it back. And at the same time I would like to "pass" a parameter to the server so that when the page is loaded I can use this parameter in the Page_Load method?
>>
>>Why not use some client code to do this with JavaScript? It seems all youwant to do is clear some values. Use OnClientClick() and then run a function that clears out the values:
>>
>>
>>function ClearVals()
>>{
>>   document.getElementById('txtName').value = "";
>>   document.getElementById('txtAddress').value = "";
>>}
>>
>>
>>This sidesteps the whole issue of posting back and otherwise submitting values that you do not want changed on the server.
>>
>>+++ Rick ---
>>
>
>I thought about what I said and I was wrong. Setting property CauseValidation() to false does not stop a button from posting back.
>Therefore, even if use the javascript, as you suggested, I don't seem to find a way to prevent the button from posting back. Even if I don't have a method OnClick(), the page "jumps" when I click on the button.
>
>I wonder if I am missing a way to stop the button click from posting back?


Set UseSubmitBehavior to false, then use OnClientClick like this:

OnClientClick="ClearVals();return false;"

This will prevent the postback from occurring. You can also return a value from ClearVals to conditionally determine whether you want to post back or not:

OnClientClick="if (ClearVals()) return false;"

Not real obvious but it works.

But if you're not using server side button behavior in the first place you can also just use an HTML button, which doesn't post back to the server at all.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform