Solved

if else block

Posted on 2006-06-27
26
225 Views
Last Modified: 2010-04-16
Hi Guys,

This might sound very simple to many of you, but being new to C# programming i am struggling to write one if else block which is mainly to compare integer values

                                      if( Int32.Parse(Request.QueryString["@cid"].Trim()) > 0)
                              {
                                    this.btnConfirm.Visible = false;
                                    this.btnclose.Visible = false;
                              }
                                                
                              if (Int32.Parse(Request.QueryString["@id"].Trim()) == 1)
                              {
                                    this.btnConfirm.Visible = false;
                                    this.btnclose.Visible = false;
                              }

The system dont seems to go in any of the if statements.....

Any help would b much appreciated.


0
Comment
Question by:radhakrishan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 12
26 Comments
 
LVL 25

Accepted Solution

by:
dstanley9 earned 250 total points
ID: 16992841
what is the value of @cid and @id?  If it's 0, it wil not enter either block.

0
 

Author Comment

by:radhakrishan
ID: 16992911
The value coming from query string is 1...
I been just trying various options...

Can there be error in incorrect conversion from string to integer?

0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16992934
Can you post the entire query string?  does your key start with "@"?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:radhakrishan
ID: 16992981
Here it is, the page is called from another page:

hyperlink1.NavigateUrl = "javascript:window.open('BookingPage.aspx?@id=" + xlrow["BookingId"].ToString().Trim() +
                              "&@cid=" + DropDownList1.SelectedValue.Trim() + "&@ctext=" + DropDownList1.SelectedItem.Text.Trim() +
                              "','newBookingPage', 'width=500,height=370, status=no toolbar=no');void(0);";
                              
As you can see the first querystring variable is @id , this wat I really need to compare if its value is 0 or >0 and if >0 whats its value.


0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16993021
Can you debug the app and look at these values:

Request.QueryString["@cid"]
Int32.Parse(Request.QueryString["@cid"].Trim()
Request.QueryString["@id"]
Int32.Parse(Request.QueryString["@id"].Trim()
0
 

Author Comment

by:radhakrishan
ID: 16993077
The values of both of them are 1,1
as i display them in one of the textboxes!
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16993107
But the buttons are still visible?
0
 

Author Comment

by:radhakrishan
ID: 16993211
yeah initally they all are invisible,
I tried the other way round too of avin them invisible first and then makin visible in if block
but no success!
0
 

Author Comment

by:radhakrishan
ID: 16993241
This is really weird if I do somthing like


int counter=1;
if(counter==1)
{
   //same code
}

Its not executed!!
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16993271
Are you debugging or just seeing the effects?  Based on your initial example, if cid > 0 or id = 1, then both buttons will be _invisible_.  Is this what you are expecting?  Or do you want tem to be visible and just have the logic flipped?
0
 

Author Comment

by:radhakrishan
ID: 16993397
I am just looking at the effect at moment,

Initially I made all the buttons invisible and try to make it visible on query string values but since that didnt work i flipped my logic! but thats no good either..

And def the values are coming from database and everywhere because I am actually converting the code from VB to C# and everythings runs as expected
with VB but unfortunately not with C#....

0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16993415
But you want the buttons to be INVISIBLE if either cid > 0 or id = 1?
0
 

Author Comment

by:radhakrishan
ID: 16993416
Debuggin the code

              string str1 = Request.QueryString["@id"].Trim().ToString();
              int st1 = Int32.Parse(str1);

value for str1 = "1"
value for st1 = 0

0
 

Author Comment

by:radhakrishan
ID: 16993435
No sorry about that value of st1 is 1...

but even though counter = 1

      if (counter==1)
                              {
                                    this.btnConfirm.Visible = false;
                                    this.btnclose.Visible = false;
                              }

it does not go into the loop.
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16993484
Again, you want the buttons to be INVISIBLE if either cid > 0 or id = 1?
0
 

Author Comment

by:radhakrishan
ID: 16993499
Yeah
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16993531
You've confirmed using the debugger that it doesn't go into the blocks or you just see that the buttons are visible?  Where are your if blocks (e.g. Page_Load)?  Could something else be setting them to visible after the if blocks?
0
 

Author Comment

by:radhakrishan
ID: 16993558
Yeah they are set in Pageload

if (!PageLoad)
{


}

All code is inside this block.
and there is no where else there properties are changed.
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16993604
You mean

if (!IsPostBack)

?

This only gets executed when the page is loaded the first time.  If you want it to execute every time, you need to put it outside of the IsPostBack block.
0
 

Author Comment

by:radhakrishan
ID: 16993625
Yeah I know, so when the person first visit the page the values and properties are set..

I am soz yea its
if( !Postback)


Its not even friday!!!

0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16993669
And you have confirmed IN THE DEBUGGER that the if block are not being executed and the values are correct?
0
 

Author Comment

by:radhakrishan
ID: 16993694
Yea def its not going into those if blocks....


0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16993761
Your IF logic is OK; something else is going on.

can you put a breakpoint on the IF statements and look at these values in the watch window:

Request.QueryString["@cid"]
Int32.Parse(Request.QueryString["@cid"].Trim()
Request.QueryString["@id"]
Int32.Parse(Request.QueryString["@id"].Trim()

And then try to step into the if blocks?
0
 

Author Comment

by:radhakrishan
ID: 16993844
I just did this:
                        string str1 = Request.QueryString["@id"].Trim().ToString();
                  int st1 = Int32.Parse(str1);
                  int st2 = Int32.Parse(Request.QueryString["@id"].ToString());

and the values are:
{1}
1
1

AS that is what we would expect it to be.
but again dont go to if and straight jumps to catch block!!
0
 

Author Comment

by:radhakrishan
ID: 16993860
I found the bug mate

its cmd.dispose()

bcoz of that it was not executing anything after that....
me bein daft!!!

Cheers for ur help though!!

Thanks
Nick
(Time to go home now! :-)))
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16993873
catch block?!?!?  You didn't say anything about a catch block.  That means an exception is being thrown.  To see the exception:

catch(Exception exception)
{
  // Look at exception.Message
}

and see what the exception says.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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