Okay so I have some c# that generated href anchor tags styled as list items and throws it onto an aspx page like so;
html += "<a href='../InspectionView.aspx' class='list-group-item' id=''>Inspection ID: " + inspectionID + " - Due Date: " + inspDueDate + " - Inspector(s): Bob Williams <span style='min-width:75px' class='label label-primary pull-right'>" + status + "</span></a>";
Now this is in a loop, the variables are pulled from a SQL database and used to populate that html string.
Now, what I'm trying to do is have it so when the user clicks on one of the generated hrefs, and is redirected to the next page, the variable inspectionID is passed forward. I thought there might be someway of storing it in the ID of the href tag but I dont know where to go from there.
Thanks a lot.
Add a query string parameter.
html += "<a href='../InspectionView.aspx?inspectionID='" + inspectionID + " class='list-group-item' id=''>Inspection ID: " + inspectionID + " - Due Date: " + inspDueDate + " - Inspector(s): Bob Williams <span style='min-width:75px' class='label label-primary pull-right'>" + status + "</span></a>";
For reading on the receiving page:
string inspectionID = Request.QueryString["inspectionID"];
See
https://msdn.microsoft.com/en-us/library/system.web.httprequest.querystring(v=vs.110).aspx
a very simple way is to stick into a query string. Since this isn't a server control it might be the only way to it.
something like...
html += "<a href='../InspectionView.aspx?InspectionID="+HttpUtility.UrlEncode(Inspection_ID.ToString())+"&anyotherQSField="+HttpUtility.UrlEncode(anyotherQSFieldVariable) + "' class='list-group-item'> - Due Date: " + inspDueDate + " - Inspector(s): Bob Williams <span style='min-width:75px' class='label label-primary pull-right'>" + status + "</span></a>";
Then in InspectionView.aspx,get values with something like:
String strInspection_ID = Request.QueryString["InspectionID"];
You likely need to convert to string for this to work for the ID.
You dont have to use HttpUtility.UrlEncode for Inspection_ID but if you have other strings you want to use in QS that might contain spaces or other odd characters - it would be wise.
Related
I have googled lots of possible answers with no luck. I am trying to extract the following from the Event Log (pseudo-code):
select events
where
event date/time between FromDateTime and ToDateTime
and
((Level<=2) // error, critical only
or
((Level<=x) and Provider[Name] in a specific list) // any messages for these apps
)
(The second "Level" expression is to allow the user to specify whether to include Informational messages or limit to Warnings and above, so I can't just discard it.)
The following is the (latest) expression I am trying to use - unsucessfully.
string queryString =
"*[System[TimeCreated[#SystemTime>='" + dFrom + "' and #SystemTime<='" + dTo + "']]] " +
" and " +
"(*[System[Level<=2]]" +
" or " +
" ( " +
" *[System[Provider[#Name='<1st name>' or #Name='<2nd name>' or #Name='<3rd name>]] " +
" and " +
"System[Level<=" + maxLevel.ToString() + "]]" +
")" +
");"
Am I trying to make an expression that is too hard for the Event Log query evaluator, or do I just have a simple error in the expression?
I have been trying various forms of the expression. It appears that the "Level" filters are just being ignored, but why?
*** ARRGGHH!! - I think I found it. The Event Log Level enumeration is:
1 - Critical alert
2 - Error
3 - Warning
4 - Informational
5 - Logs at all levels
... and ...
0 - Undefined - indicates logs at all levels
It turns out that some of the "Information" log entries from Microsoft components use Level 0 instead of 4, so these are being picked up by the filter.
My assumption that log entries (especially Microsoft's) would use the appropriate Level was false.
I will need to explicitly look for (Level=1 or Level=2) - Level <= 2 will pick up various Microsoft "Information" log entries.
For anyone interested - the final working query is:
*[System[TimeCreated[#SystemTime>='2018-07-30T17:22:30.000Z'
and #SystemTime<='2018-07-30T20:22:30.000Z']
and (Level=1 or Level=2 or
(Provider[#Name='Application Error' or #Name='Application Hang']
and (Level=1 or Level=2 or Level=3 or Level=4)))]]
There are two issues that I can see in the code that you had posted.
the single quote is not closed on the 3rd name: #Name='<3rd name>]] should be #Name='<3rd name>']]
the second filter for */System/Level should be *[System[Level<=" + maxLevel.ToString() + "]]] "
From your pseudo code and what you have shared, it looks like you could consolidate and move some of your logic inside of the predicate filter for */System and use an XPath such as:
string queryString =
"*[System[TimeCreated[#SystemTime>='" + dFrom + "' and #SystemTime<='" + dTo + "']" +
" and (Level<=2 or " +
" (Provider[#Name='<1st name>' or #Name='<2nd name>' or #Name='<3rd name>'] " +
" and Level<=" + maxLevel.ToString() + "))" +
"]];"
I am using the following code to give blank space so that the three elements "label, then dropdown and then a button for action on dropdown" are right aligned in a panel in a web page.
Now, I know I can do with padding/margin, however, it all works only with respect to the element at right side and not from the right hand side of the browser.
However, I was talented enough to achieve what I want using but I find it weird to write the code this way:
LiteralSpecial.Text = " " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"Select page ";
Is there are way to refine this please, folks?
Have you tried using CSS?
<div style="text-align:right">Select page</div>
See it in action: http://jsfiddle.net/vhxchyrj/2/
<div style="width:600px;padding-left:550px;">Select page</div>
I Have a messagebox to display some text and data (if existing) within database. The current Issue is trying to show nulls and trying to convert to ShortDate. I've taken two approach but none quite work in the way I need.
The first approach uses Ternary concatenation within the string but it behaves really weird.
DialogResult DuplicateMessage = MessageBox.Show("A contact name " + DuplicateName.Forename + " " + DuplicateName.Surname + " already exists within the System."
+ "\n Existing Client: " + DuplicateName.Forename + " " + DuplicateName.Surname
+ "\n Date of Birth: " + DuplicateName.DOB != null ? Convert.ToDateTime(DuplicateName.DOB).ToString("yyyy-mm-dd") : " ",
,"Possible Duplicate Client", MessageBoxButtons.YesNo);
Currently The message box only shows the line breaks and the Date Of birth. Not even the text "Date of Birth"
If I remove Tertiary and conversion and simply have
DialogResult DuplicateMessage = MessageBox.Show("A contact name " + DuplicateName.Forename + " " + DuplicateName.Surname + " already exists within the System."
+ "\n Existing Client: " + DuplicateName.Forename + " " + DuplicateName.Surname
+ "\n Date of Birth: " + DuplicateName.DOB
,"Possible Duplicate Client", MessageBoxButtons.YesNo);
This works, shows everything. Only issue is that the Date of birth is in the wrong format. Was wondering how do I make it so the date is in short date format and will show everything.
all Properties Of 'DuplicateName' are nullable,
I suspect this is a problem with operator precedence using the conditional operator. It's likely including string concatenations as part of the condition being tested, rather than as part of the result. You can explicitly enclose the elements of that operator with parentheses to identify which strings belong therein and which do not:
"\n Date of Birth: " + (DuplicateName.DOB != null ? Convert.ToDateTime(DuplicateName.DOB).ToString("yyyy-mm-dd") : " ")
Additionally, if DOB is a DateTime? then you can simplify your code a little:
"\n Date of Birth: " + (DuplicateName.DOB.HasValue ? DuplicateName.DOB.Value.ToString("yyyy-mm-dd") : " ")
There's no need to use Convert on Nullable<T> types, you can more easily (and safely) make use of the HasValue and Value properties.
You can fix it by using another pair of parentheses:
(DuplicateName.DOB != null ? Convert.ToDateTime(DuplicateName.DOB))
In your first case, you're concatenating a huge string together (because you don't use any parentheses) and then testing that for null. It's equivalent to this:
var stringToTest = "A contact name " + DuplicateName.Forename + " " + DuplicateName.Surname + " already exists within the System."
+ "\n Existing Client: " + DuplicateName.Forename + " " + DuplicateName.Surname
+ "\n Date of Birth: " + DuplicateName.DOB;
DialogResult DuplicateMessage =
MessageBox.Show(stringToTest != null ? Convert.ToDateTime(DuplicateName.DOB).ToString("yyyy-mm-dd") : " ",
,"Possible Duplicate Client", MessageBoxButtons.YesNo);
Hey guys I am trying to print a list of responses from an API into labels and one issue I have is that the response (from JSON) is a string with a shortened link in it. When I put that string into a label the link is not recognized as a link the browser just think it is HTML so there is no underline or pointer. How can I solve this? I have already tried to HtmlEncode it and that did not help.
Here is what I am trying to do.
lblResponse.InnerHtml += "<strong>created_at:</strong> " + item.created_at
+ "<strong>  text:</strong> " + HttpUtility.HtmlEncode(item.text) + "<br />";
Which returns this into the label. Though in my browser the shortened link is not recognized as a link. Advice?
created_at: Tue Apr 16 20:30:32 +0000 2013 text: Here is some social media news for the week... http://t.co/RR5DKvqUjd
Thanks in advance for the help.
var date = "Tue Apr 16 20:30:32 +0000 2013";
var text = "Here is some social media news for the week... http://t.co/RR5DKvqUjd";
var textwithanchor = Regex.Replace(text, #"\(?\bhttp://[-A-Za-z0-9+&##/%?=~_()|!:,.;]*[-A-Za-z0-9+&##/%=~_()|]", delegate(Match match)
{
return string.Format("<a href='{0}'>{0}</a>", match.ToString());
});
var html = "<strong>created_at:</strong> " + date + "<strong>  text:</strong> " + textwithanchor + "<br />";
Regex gracefully borrowed from here: http://www.codinghorror.com/blog/2008/10/the-problem-with-urls.html but please take note of the caveats.
Try something like this:
lblResponse.InnerHtml += "<strong>created_at:</strong> " +
item.created_at +
"<strong>  text:</strong> " +
"<a href=\"" + item.text + "\"" +
HttpUtility.HtmlEncode(item.text) +
"</a><br />";
I have two javascript functions, insertAddedSup and removeAdded. When I retrieve values from a table and populate a control with this information, the onclick event inserts the user and the "Remove" button works fine. When I use LDAP to search for a user, and I click on the user, all of the html is correct (shows the correct parameters being sent to the remove function - just like the SQL result), but when I click on the remove button, the value of the parameter being used in the function is different from that which shows up in the html. I don't recognize the value from anywhere... it seems almost random, though it is always the same value. Not sure what to do. Does anyone know what might be the problem?
Here are the functions:
function insertAddedSup(uidSup, fullnameSup) {
var fullnameSup = fullnameSup.toLowerCase();
var currentContentSup = '<div id="y_' + uidSup + '" class="selectedDataBox" style="overflow:hidden;"><span style="text-transform:capitalize; float:left">' + fullnameSup + '</span><input type="hidden" name="EmpID" id="personAddedSup_' + uidSup + '" value="' + uidSup + '"><input type="button" name="removeAdded_' + uidSup + '" id="removeAdded_' + uidSup + '" value="Remove" onclick="alert(' + uidSup +');removeAdded(' + uidSup + ');" style="font-size:0.7em; float:right; width:60px;"></div>';
$('#addedPerson').html(currentContentSup);
alert($('#addedPerson').html());
$('#addedPerson').show();
$('#MainContent_searchContent_btnSubmitEmployee').attr('disabled', false);
}
function removeAdded(uidSup) { // hide the div of the person added
var divID = "#y_" + uidSup;
alert($('#addedPerson').html());
$(divID).hide();
$(divID).remove();
if ($('#addedPeople').html() == '') {
$('#addedPeople').hide();
}
$('#MainContent_searchContent_btnSubmitEmployee').attr('disabled', true);
}
I added some alerts so that I can see what is actually being sent, what is in the html, etc.
Edit: HTML
<div id="y_0730337" class="selectedDataBox" style="overflow:hidden;">
<span style="text-transform:capitalize; float:left"></span>
<input name="EmpID" id="personAddedSup_0730337" value="0730337" type="hidden">
<input name="removeAdded_0730337" id="removeAdded_0730337" value="Remove" onclick="alert(0730337);removeAdded(0730337);" style="font-size:0.7em; float:right; width:60px;" type="button">
</div>
It also seems to work ok if the number does not start with a 0. Is there some way that I can make sure that the value is treated as a string?
In your button onclick:
onclick="alert(0730337);removeAdded(0730337);"
These are being treated as numbers and not strings because you don't have quotation marks around the parameters. If a number begins with a 0 the number will really begin with the next non zero number (in this case 7) making the value passed 730337 (I honestly don't know why what you see as the actual value passed is so vastly different though. I'd be interested in hearing if someone else had an explanation for this).
What you really want is:
onclick="alert('0730337');removeAdded('0730337');"
You saying numbers that don't begin with a 0 work make me believe that this is why you are having this problem.