Solved

if else block

Posted on 2006-06-27
26
219 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

15 Experts available now in Live!

Get 1:1 Help Now