|
Don't throw a "global exception", throw an Application Exception
throw new ApplicationException($"The role '{role.RoleName}' cannot be deleted because it has users assigned to it." );
You can then catch just those and report them:
catch (ApplicationException aex)
{
MessageBox.Show(aex.Message);
return;
}
catch (Exception ex)
{
... Or better, don't throw an exception if your code is going to handle it in the same method - report the problem directly in your code instead, and return from the method.
Exceptions shouldn't be used as a form of flow control!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You shouldn't use exceptions for things that are expected. If dealing with deleting roles that might have users attached is part of your business logic flow then it isn't an exception, it is a predicted possible outcome. If there is only one way the remove could fail (barring actual exceptions like your database not being available etc) then make your method return a bool and return false if the role has users and your calling code can report that to the UI. Or you could return an enum that has values like
Success
RoleHasUsers
SomeOtherPossibleFailure
and return the appropriate enum and again have the calling code report to the UI.
|
|
|
|
|
Kevin Marois wrote:
catch (Exception)
{
throw;
} If your catch block is simply re-throwing the same exception, without adding any extra information to it, then you don't need the catch block at all.
And as Griff said, don't use throw new Exception(...); - use a specific exception type instead. Either one of the built-in exception types, or a custom exception type will do. That way, the calling code has a better chance of catching just the exceptions it can handle, without having to look at the Message to try to work out what the problem is.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I give the user the option to retry at the application level instead of abandoning them with a "shut down".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Ive already searched for infomation how I can do that but I cant fix this problem. I want to add a weather-widget to my webpage. It works using latitude and longitude. I want it should desplay the current weather from where the user is now.
<span id ="long"></span>
<script type='text/javascript' id="weather-link" src='https://darksky.net/widget/default/></script>
<script>const weatherLink = $("#weather-link");
weatherLink.html("<span id=\"" + response.latitude + "," +response.longitude + "\">/uk12/de.js?width=100%&height=350&title=Basel&textColor=333333&bgColor=FFFFFF&transparency=false&skyColor=undefined&fontFamily=Default&customFont=&units=uk&htColor=333333<Color=333333&displaySum=yes&displayHeader=yes</span>");
weatherLink.attr("src", weatherLink.attr("src") + response.city);</script>
The following code I use it to get users information. It works well
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$("#long").html(response.latitude + ", " + response.longitude );
$("#response").html(JSON.stringify(response, null, 4));
}, "jsonp");
</script>
I need to add to src a text that changes using that code above. THX
|
|
|
|
|
|
[edit]Hidden links deleted.[/edit]
|
|
|
|
|
We aren't a code-to-order service.
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Hi,
I'm working on a file sharing application and want to open a certain form when the user right click on any file on windows explorer.
I managed to add an option to the context-menu that launches the application, but it opens a new instance. The application is already running in the background (in system tray), so I want to access the currently running application (not a new instance) and be able to show a certain form that displays the connected users. Is this possible or what?
Thanks
|
|
|
|
|
|
Thanks bro, this was useful but I was hoping to close the other instance and stick to the first one.
|
|
|
|
|
That's exactly what it does ... it passes the new file info through to the original instance and then shuts itself down.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Oh sorry that's great, really Thank you.
|
|
|
|
|
You're welcome!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have a task to do. I need to get the value from the tag into c#. I need to display the value into Label. This here is my HTML code:
<pre><div size="10" id="para1"></div> <p></p><asp:Label ID="Label2" runat="server" Text="" Font-Size="XX-Large"></asp:Label><p></p><asp:Label ID="Label3" runat="server" Text="" Font-Size="XX-Large"></asp:Label>
<script>
document.getElementById("para1").innerHTML = formatAMPM();
function formatAMPM() {
var d = new Date(),
days = ['sonday', 'monday', 'tuesday', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];
return days[d.getDay()];
}</script>
from code behind i use this here to get the value but it does not work:
HtmlDocument page = new HtmlWeb().Load(@"D:\Downloads\wichtig\try\WebApplication1-Kopie-Kopie\MeineWebseite\löschen\WebForm2.aspx");
var title = page.DocumentNode.SelectSingleNode("//div[@id='para1']");
Label3.Text = title.ToString();
I only know how to get the tag by Id. This is how it works
document2.Load(@"D:\Downloads\wichtig\try\WebApplication1-Kopie-Kopie\MeineWebseite\löschen\WebForm2.aspx");
string tag = document2.GetElementbyId("para1").Name;
Label2.Text = tag;
That is how it works but I want Label3 should display the current date like
<div>id="para1</div>
The result is this here https://i.stack.imgur.com/wes2a.png
|
|
|
|
|
This question doesn't make a lot of sense.
You're opening an .aspx page directly from disk. This will return the raw ASP.NET file, not the generated HTML markup.
You're then trying to read the value of an element which is set by Javascript. But the HtmlAgilityPack won't execute the Javascript, so the element won't be initialized.
If you just want the German name of the current day in your label, you can do that directly:
var culture = System.Globalization.CultureInfo.GetCultureInfo("de-DE");
Label2.Text = DateTime.Today.ToString("dddd", culture); If you want to use the current culture, it's even easier:
Label2.Text = DateTime.Today.ToString("dddd");
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello everyone, I'm trying to configure LED8 customer display. In my customer display there are 4 prefix text eg:“Price”、“Total”、“Collect”、“Change” but i cannot light up that prefix text. I try using some command to connect COM port.
C: \> MODE COM1 2400, N, 8,1
C: \> TYPE CON> COM1
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So tell us what code you might have used, what you typed, what the manual says the display expects. What the manufacturer says should happen - you did check the website, didn't you?
We can't help you based on "I've got a box and it doesn't work" - which is pretty much all you have told us so far!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'm not sure what you think anyone can tell you based on this little bit of information.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
"LED8 customer display" means absolutely nothing to anyone but you.
We have no idea what this device is, how it communicates (there is not standard for this!), what the protocol is, what commands it accepts, ... NOTHING.
...and you want help with the very thing you didn't describe to us.
By the way, typing those commands into a CMD Prompt on Windows today does absolutely nothing.
|
|
|
|
|
|
Project
So I have a form with windows media player,and a couple of other stuff on it.
What I want to be able to do is the following.
Using my phone, I would like to be able to control that media player from my browser.(On a local network)
Example.
I am in a other room and I want to skip the current song. I'd go into the browser open a page. Click on skip and the player will skip to the next song in the list.
I'd love if someone could give tips like the following example.
1. Create your application.
2. Create a server.
3. Create an html page.
4. Link the stuff
|
|
|
|
|
1. Create your application.
2. Create a server.
3. Create an html page.
4. Link the stuff What more do you need to know?
You need the app you write to set up something to "Listen" for instructions, or to connect to the web app to get it's instructions from there.
You need the web app (running locally on the LAN) to talk to the app.
3) You need to do this, and also write code-behind code to talk to the player app.
One way to do it is using a Socket - have a look at the Sockets stuff in here: Double Clicking a File in Explorer and Adding It to Your App while it's Running[^] and also here: Socket Class (System.Net.Sockets) | Microsoft Docs[^] for one way to do it. You set up a listener on the player app, and then open a connection on the webserver app to send the commands.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: What more do you need to know? THe codez, duh!
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|