?
Solved

if else block

Posted on 2006-06-27
26
Medium Priority
?
226 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 750 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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