473,287 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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 1919
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steve Meier | last post by:
Environment: SQLServer Developer Edition on Machine A Enterprise Manager running on remote machine B Both machines are in the same subnet I open Enterprise Mgr on Machine A, right click...
9
by: AFN | last post by:
I was just dropped into someone else's code (isn't that always so fun?). I can't figure out why a custom validation control's server event function is executing. There is nothing (that I see)...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
4
by: Kash | last post by:
Hi everybody: I've developed a web application running on a 2003 server not on the web but on extranet environment of a small Firm (less than 10 users). I've taken benefit of Office Primary...
3
by: Paul | last post by:
Hi all, I've been trying unsuccessfully to stop client side event validation. I've created a simple page with a text box, a required field validator and a server button with the following...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
2
by: moondaddy | last post by:
I had to repost this because I had to update and change my msdn alias. I will re-ask the question and clarify a few things that were not clear before. This code is all executed on my dev...
2
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.