Label null exception [closed] - c#

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am receiving a null exception every time I try to send the HttpContext.Current.User.Identity.Name to the label. Any ideas why?
This is what im using.
String Utilizador = Page.User.Identity.Name;
Response.Write(Utilizador);
Label1.Text = Utilizador;

Since you are authenticated and you're getting the NullReferenceException in Label1.Text = Utilizador;, you don't have a reference to that label.
everything is in master page for now
Rename it on the MasterPage, compile it, name it again Label1(i would strongly recommended to use better names for example LblUserName). Then recompile it.

You need to disable non-authenticated users. In web.config:
<authorization><deny users="?" /></authorization>

You need to instantiate your Label
Label Label1 = new Label();
Label1.Text = Utilizador;

Could you try to add authentication tag in web.config as below.
<authentication mode="Windows" />

Related

C# CodeDom Cant type in " [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I want to compile a code with codedom which should connect to my ftp server.
But I cant type in the credentials because of the ""...
Look here :
Temp.AppendLine(#"request.Credentials = new NetworkCredential("userid","userpassword");");
If I type " in the code, it automatic ends the content of the brackets...
Help?
You may need to escape the content by using double quotes, like this:
Temp.AppendLine(#"request.Credentials = new NetworkCredential(""userid"",""userpassword"");");
Temp.AppendLine(#"request.Credentials = new NetworkCredential(""userid"",""userpassword"");");
Escape the " with ""

Check radio button in RadioButtonList based on value read from database [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I have a RadioButtonList and I would like to select a radio button in this list based on a value read from a database. Once I read the value from the database, how do I then make the radio button in the list become selected?
You can simply assign the value via RadioButtonList.SelectedValue = reader.value; as long as you know that the value is in the list (if it's not in the list, then you will get an exception when that line executes).
Since it sounds like you do not know for sure that reader.value will be one of the options in the RadioButtonList, so you will need to check that first.
if(RadioButtonList.Items.FindByValue(reader.value) != null) {
RadioButtonList.SelectedValue = reader.value;
}
Alternatively, you could handle the exception via a try/catch.
string sSortname = row["GoodsSortName"].ToString().Trim();
foreach (ListItem s in this.rdbSort.Items)
{
if (s.Text == sSortname)
{
s.Selected = true;
break;
}
}
I Used this way ,had sovle this problem

How to get Complete QueryString? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
How can I get complete querystring in asp.net?
Suppose a QueryString like this passed to my Login Page.
login.aspx?redirect=cart.aspx&p=1&q=2&r=3
I have to pass parameters p,q and r to Cart.aspx with all of the parameters except redirect.
Login.aspx may handle different querystrings but all parameters except the redirect are to be passed to the redirecting page.(Actually, I know there will be a parameter 'redirect' but can't write code for p,q,and r bcoz it may change in different contexts)
The parameters except 'redirect' will be different in different contexts. The p,q,r are required parameters for cart.aspx. If the redirection is to another page then the parameters may not be p,q,r instead something else like l,m,n
You can use like this
Request.Url.Query
Input like this
Input: http://localhost:96/Cambia3/Temp/Test.aspx?q=item#fragment
Output
You can get the parameters using
string _url=Request.RawUrl.toString();
and
For path ...
string _path = Request.Path.ToString();
string _url = Request.ServerVariables["URL"].ToString();
O/P = /Home/About/
RawURl Returns whole querystring....

How can I get from a string of a directory and file name only the file name? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
The code:
'Files' is a List<string> and _indx is an int.
label22.Text = files[_indx];
For example in 'files' in index[0] I have this string:
D:\New folder (45)\converted.avi_Automatic\Lightning 0 Length 2 [91 - 93]\000091.bmp
But instead in label22.Text I want it to show me only '000091.bmp' without the rest of the directory path.
How can I do it ?
Use Path.GetFileName:
label22.Text = Path.GetFileName(files[_indx]);
I believe you are looking for Path.GetFileName():
label22.Text = Path.GetFileName(files[_indx]);
Path.GetFileName(fileName) returns the file name without the directory.
taken from http://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=vs.100).aspx
The simplest way is
Path.GetFileName(files[_indx]);

explicitly casting generics in C# 4 [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
Can anyone help me in casting generic collection in c# 4.
Here is the code snippet.
GridView1.DataSource = dataServiceColl.Select(t => t.product_desc="EdibileItem")
It is throwing up runtime error at the below line,
Gridview1.Databind();
Saying it is a HTTP Exception.
I think it should be a simple type cast.
Thanks,
Kris.
Use
t => t.product_desc=="EdibileItem"
HTTP Exception? That has nothing to do with casting.
More importantly, why are you assigning "EdibleItem" to t.product_desc here?
Select(t => t.product_desc="EdibileItem")
Did you meant == instead of =? If so, would a Where be more appropriate than a Select?
I think it all boils down to: what are you trying to achieve, exactly?

Categories