?
Solved

return issue

Posted on 2011-10-25
16
Medium Priority
?
197 Views
Last Modified: 2012-05-12
I have a function returns "false" than on code behind on button click event I say if my function == "false" pop up a javascript alert message and than I say return; but return doesnt stop page to return to same page... it doesnt work.. what I need to do ?
0
Comment
Question by:1jaws
  • 8
  • 8
16 Comments
 
LVL 7

Expert Comment

by:dimaj
ID: 37025583
is this C# question or javascript?
if it's javascript, use this syntax:
var returnVal = someFuncCall();
if (returnVal === false) {
   alert ("function returned false");
}
0
 

Author Comment

by:1jaws
ID: 37026223
it is C# code behind..
 and in my function I do like that

if (reader.HasRows)
                {
                    return "false";                    
                }
                else
                    return "true";


if (functions.Checkme(txtAddress.Text.Trim()) == "false")
            {
               
                string textForMessage = @"<script language='javascript'> alert('Address you entered already exists.');</script>";
               ClientScript.RegisterClientScriptBlock(this.GetType(), "UserPopup", textForMessage);
               return; <---- this return doesnt return the back to page
             }
0
 
LVL 7

Expert Comment

by:dimaj
ID: 37026274
What's the implementation of Checkme?
What does it return? Judging by the name of the function, it returns a boolean, which of course will not equal a string.
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 

Author Comment

by:1jaws
ID: 37026651
it returns above "true" false as I showed above.... if has rows comes back from sp it returns "false" but not as booleen... thats why I put inside the code...
0
 
LVL 7

Expert Comment

by:dimaj
ID: 37026686
wait... so, you're in your 'if' statement and you're seeing your popup message?

what do you expect your return statement do?
0
 

Author Comment

by:1jaws
ID: 37026878
see I have radtabs that so goes on the next page I need to stay into same page because it returned false,
0
 
LVL 7

Expert Comment

by:dimaj
ID: 37026886
and right now it still goes on to the next page?
0
 

Author Comment

by:1jaws
ID: 37026890
yes it does
0
 

Author Comment

by:1jaws
ID: 37026901
I should have said... that (function) is class that I called as a function. ..... it is not javascript function...
0
 
LVL 7

Expert Comment

by:dimaj
ID: 37026909
who's calling your function where you have you 'if' statement?
0
 

Author Comment

by:1jaws
ID: 37026953
I attached the all  code...
code.txt
0
 
LVL 7

Expert Comment

by:dimaj
ID: 37027084
I'm not sure why, but it seems (after quick research) that sequence of events in asp.net is as follows:
user clicks a button -> page_Load event is called -> button click event is called

you might want to add some logic in the page_load event to wait for button click to finish and depending on the outcome, either go back or continue with page loading.

also, check to see if there's a page unload event (or something like that) and see when it is called. if it called before page_load, then wait for button's event handler to finish in unload.

I hope this makes sense.
0
 

Author Comment

by:1jaws
ID: 37027152
instead of doing this button click event code behind.. how about creating a javascript function and do it  there onblur or something? how can I do that?
0
 
LVL 7

Accepted Solution

by:
dimaj earned 2000 total points
ID: 37027341
just have an input button that will trigger a javascript code. If result is success, then invoke page load for the new page, else stay on the current page.

Unfortunately, I can't help you with the code there as I don't know how to do that :(
0
 

Author Comment

by:1jaws
ID: 37027510
Thank you for all your effort.. I 'll do it rest...
0
 
LVL 7

Expert Comment

by:dimaj
ID: 37027548
no problem! I'm sorry I couldn't be more help here :(
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question