Peter
With you great lead .. here is what I came up with (with some help from a
post in a newsgroup)
AND.. it works (which is always a plus)
var oldPostBack
function window.onload() {
oldPostBack=__doPostBack;
__doPostBack=MyPostBack;
}
function MyPostBack(Param1, Param2) {
if (document.all('lblDictationMode').innerHTML!='') {
alert('Please finish or cancel your edit/creation of the current
dictation before selecting a new patient.');
document.all('lblUserMessage').innerHTML=''; }
else {
if (typeof(oldPostBack)=='function') oldPostBack(Param1,
Param2); } }
Now my site displays the message and doesn't post so everything stays right
where it was and allows the user to click the save button if they whish,
else it acts normally.
This is a better solution, as it doesn't matter what control caused the
postback. I will catch it, before I was just working on the datagrid
(scrollinggrid).
Thanks again, I would have never thought of that __doPostBack function. You
da MAN !!!
Jon
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:82**********************************@microsof t.com...
This is "pseudocode" but the pattern would be something like this:
function CheckDictationMode()
{
if (confirm(...)) __doPostBack(...);
}
Dim btnView As LinkButton = e.Item.Cells(0).Controls(0)
btnView.Attributes.Add("onclick", "CheckDictationMode();")
-- if the confim(which shows your message) returns false, the __doPostBack
is not called.
You'll have to experiment a bit, but that pattern should do it. You may
have
disable the autopostback on the control, since you'll be deciding whether
it
posts back or not now.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Jon Delano" wrote:
Hi
I was wondering if it were possible to somehow stop a page from posting
back
to the server and running the server side code.
I have a datagrid and the first column is basically a button.
I have added a javascript function to the button :
Dim btnView As LinkButton = e.Item.Cells(0).Controls(0)
btnView.Attributes.Add("onclick", "CheckDictationMode();")
here is the javascript function
function CheckDictationMode() {
if (document.all('lblDictationMode').innerHTML!='') {
alert('Please finish or cancel your edit/creation of the current
dictation before selecting a new patient.');
return false;
}
else {
DisplayDataRequestMessage();
}
}
In the javascript function, I check the contents of a hidden field, if
the
field doesn't have what I like then I display a message to the user and I
don't want the codebehind code to run (there is server side code that is
executed when the grid is clicked)
Currently I do get the message, but the form still gets submitted to the
server.
I found a bunch of stuff about simply returning false. I tried having the
onSubmit event of the form run the CheckDictationMode function using
onSubmit="return CheckDictationMode()". That never even seemed to fire at
all as I never received the message.
This is a Visual Studio 2003 web application using vb.net.
Also, this application is an inhouse deal, and only runs in IE .. so if
there is a VBScript alternative. I am all ears.
Any help would be greatly appreciated !!!!!
Thanks
Jon