Variable Declared
-
Dear All, Is there any way that we can check if a specific variable is declared or not Thank you! M. Nauman Yousuf
"Mess with the Best, Die like the rest"
-
Dear All, Is there any way that we can check if a specific variable is declared or not Thank you! M. Nauman Yousuf
"Mess with the Best, Die like the rest"
M. Nauman Yousuf wrote:
Is there any way that we can check if a specific variable is declared or not
Perhaps using reflection. However, if a solution contains the words "using reflection", it's usually an indication that you are thinking backwards somehow. What is it that you are trying to accomplish really?
--- single minded; short sighted; long gone;
-
Dear All, Is there any way that we can check if a specific variable is declared or not Thank you! M. Nauman Yousuf
"Mess with the Best, Die like the rest"
You can use reflection, but it seems odd to me that you wouldn't know, that's a compile time thing.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Dear All, Is there any way that we can check if a specific variable is declared or not Thank you! M. Nauman Yousuf
"Mess with the Best, Die like the rest"
M. Nauman Yousuf wrote:
Is there any way that we can check if a specific variable is declared or not
Yes. Use Reflection for that.
SSK.
-
M. Nauman Yousuf wrote:
Is there any way that we can check if a specific variable is declared or not
Perhaps using reflection. However, if a solution contains the words "using reflection", it's usually an indication that you are thinking backwards somehow. What is it that you are trying to accomplish really?
--- single minded; short sighted; long gone;
I am designing a simple display / edit page, by passing a variable in the url of that page. On page load i check for the variable and populate the edit more form accordingly. But always get an error if the variable is not present. A simple technique of try catch would be my final option if no other alternative is available Thank you! M. Nauamn Yousuf
"Mess with the Best, Die like the rest"
-
I am designing a simple display / edit page, by passing a variable in the url of that page. On page load i check for the variable and populate the edit more form accordingly. But always get an error if the variable is not present. A simple technique of try catch would be my final option if no other alternative is available Thank you! M. Nauamn Yousuf
"Mess with the Best, Die like the rest"
I recommend reading the guide on how to ask questions, so they can be understood. Also, this is an ASP.NET question. However, the answer to what you're asking now ( as opposed to what you asked before ) is that, trivially, the query string is available to you as part of the URL, or as a collection of variables. You can iterate through it for the value you need, or look for it within the string. This does not require reflection, in fact the query string variables do not exist as variables in your code, until you declare them and search for the values in the query string to set them.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
I am designing a simple display / edit page, by passing a variable in the url of that page. On page load i check for the variable and populate the edit more form accordingly. But always get an error if the variable is not present. A simple technique of try catch would be my final option if no other alternative is available Thank you! M. Nauamn Yousuf
"Mess with the Best, Die like the rest"
Do you mean if the variable is part of the url...
http://www.mysite.com//myPage.aspx?MyVariable1=this&Variable2=that
And you want to check for MyVariable1 or MyVariable2 existing in the Request collection?"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
-
I recommend reading the guide on how to ask questions, so they can be understood. Also, this is an ASP.NET question. However, the answer to what you're asking now ( as opposed to what you asked before ) is that, trivially, the query string is available to you as part of the URL, or as a collection of variables. You can iterate through it for the value you need, or look for it within the string. This does not require reflection, in fact the query string variables do not exist as variables in your code, until you declare them and search for the values in the query string to set them.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Cheers CG - that's twice you've just beaten me to it, but I'm not deleting my answer this time.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
-
Do you mean if the variable is part of the url...
http://www.mysite.com//myPage.aspx?MyVariable1=this&Variable2=that
And you want to check for MyVariable1 or MyVariable2 existing in the Request collection?"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
yes Malcolm thats exactly the case
"Mess with the Best, Die like the rest"
-
yes Malcolm thats exactly the case
"Mess with the Best, Die like the rest"
-
if(string.IsNullOrEmpty(Request.QueryString["myVariable"])) { // the variable does not exist in the URL }
J4amieC wrote:
if(string.IsNullOrEmpty(Request.QueryString["myVariable"])) { // the variable does not exist in the URL }
Actually, if the string is an empty string, the variable does exist in the url.
if (Request.QueryString["myVariable"] == null) {
// the variable does not exist in the URL
}if (string.IsNullOrEmpty(Request.QueryString["myVariable"])) {
// the variable does not exist in the URL, or is empty
}--- single minded; short sighted; long gone;
-
I am designing a simple display / edit page, by passing a variable in the url of that page. On page load i check for the variable and populate the edit more form accordingly. But always get an error if the variable is not present. A simple technique of try catch would be my final option if no other alternative is available Thank you! M. Nauamn Yousuf
"Mess with the Best, Die like the rest"
try-catch is two orders of magnitude easier than reflection !
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }