Solved

if else block

Posted on 2006-06-27
26
220 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now