469,890 Members | 1,642 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Stopping the Server Side code from running ?

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
May 19 '06 #1
3 1737
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

May 19 '06 #2
Peter

Thanks for the quick response !!
Very interesting approach..... I am using a 3rd party control called
ScrollingGrid 1.1 (Interscape Technologies) I like it a lot.
When I mouse over the linkbuttons in my first coloumn I see each row is
"javascript:__doPostBack(gridname_row_col,'')" calls.

So I am thinking it is already overriding the __doPostBack functionality.
I am emailing them to ask if there is away I can override the call of each
row to my own function that I can then make the decision on whether to
display my message or postback as normal.

Thanks again for the great lead.
Jon

(cool site you have there too)

"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

May 19 '06 #3
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

May 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by serge calderara | last post: by
4 posts views Thread by Kash | last post: by
3 posts views Thread by Paul | last post: by
2 posts views Thread by moondaddy | last post: by
2 posts views Thread by Steve | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.