Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Stopping the Server Side code from running ?

Reply
Thread Tools

Stopping the Server Side code from running ?

 
 
Jon Delano
Guest
Posts: n/a
 
      05-19-2006
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      05-19-2006
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
>
>
>

 
Reply With Quote
 
 
 
 
Jon Delano
Guest
Posts: n/a
 
      05-19-2006
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]" <> wrote in message
news:82EAB426-EB0C-4B99-9793-...
> 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
>>
>>
>>



 
Reply With Quote
 
Jon Delano
Guest
Posts: n/a
 
      05-19-2006
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]" <> wrote in message
news:82EAB426-EB0C-4B99-9793-...
> 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
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LinkButton Client side code firing before server side code alexmac262@hotmail.com ASP .Net 1 03-22-2007 06:13 PM
server side code access the text of <asp:label> changed by client-side javascript code? nick ASP .Net 3 12-15-2004 06:26 PM
how client-side presentation code interact with server-side processing code? jrefactors@hotmail.com Javascript 1 12-08-2004 01:00 AM
how client-side presentation code interacts with server-side sorting/filter code? jrefactors@hotmail.com Java 1 12-08-2004 12:30 AM
how client-side presentation code interact with server-side filter/sort processing code? jrefactors@hotmail.com Javascript 0 12-07-2004 11:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57