|
The clicks are on the client-side, not the server-side and should never be injected through server-side. That said, you can simulate the click in JavaScript easily, or if the purpose is to just trigger the function you can call the function on the body's load event as well. That would be much better and semantically correct code in your application.
<body load="onLoadFunc()">
<!--
</body>
Then you can write the function, that gets executed on the load,
function onLoadFunc() {
showImage();
}
This will execute the function, as soon as the body finishes loading, thus on the page load. This will be a better approach, as compared to any of the code injections from server.
load - Event reference | MDN
If you want to get a response from the server, and then execute the code on client-side, then I would recommend that you read a bit about Ajax first. Ajax will let you do that easily, that is also JavaScript based service, so please learn more of JavaScript here to perform tasks on client-side.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Prasadaknair wrote: My aspx page is already opened in a chrome browser. When the above code is executed, I want the javascript alert in the showImage() function to be displayed in the Default.aspx page in the same browser window itself.
You're loading the page in an external process, and expecting the response to affect the page in a totally different process?
That's never going to work, for obvious reasons.
If you want to control an existing browser, you'll need to look at using something like Selenium WebDriver[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am trying to fetch data from an API using C# but every time i get 404 error. What can be the problem, is the API is prevented by my firewall or anti virus problem. The API url is totally correct and I have checked it many times.
|
|
|
|
|
What happens if you try to access the API URL directly from your browser?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
404 Not Found Error means that the resource you were trying to reach could not be found on the server. Check if you pointing it correctly.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
You also get a 404 if the firewall is blocking the request, or the host-file is blocking it. It is a rather generic connection-error.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You should be sure that where you're calling the API can be called/reached. I mean, for ex if your App URL is http://localhost/web/home/index make sure that when you call the API can be reached from that URL.
I've happened that when I create an API of Users is only reached by the URL http://localhost/web/user/index (example) and not from http://localhost/web/home/index
A solution can be create a Route, and specify it in the API's method .
|
|
|
|
|
I have been struggling with what Jeff Atwood calls VS's "bastardized regular expression syntax" [^].
Along the way, I found Peter Macej's very useful VS extension for multiple-line-search-replace [^].
It kind of warps my mind that VS, at this late date, doesn't have a built-in multi-line search and replace, and doesn't support a more "standard" RegEx syntax !
Using 'Find in Files' in VS it's easy to limit the search to specific types of files, like *.cs.
Where I am stumped is how to select files that have specific text (keyword) content, and then apply S&R to only the matching files.
The goal is to apply the search replace only to the content in 'file1.cs
While all this is easy to do in UltraEdit (which offers UNIX and Perl regex flavors in addition to its own syntax), I'd like to know if this is possible in VS.
thanks, Bill
«Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.» Miss Piggy
modified 8-Jun-17 7:30am.
|
|
|
|
|
BillWoodruff wrote: I have been struggling with what Jeff Atwood calls VS's "bastardized regular expression syntax"
That only applies to VS2008 and earlier. Since VS2012, the search & replace uses standard .NET regular expressions[^].
Visual Studio uses .NET Framework regular expressions to find and replace text.
Before Visual Studio 2012, Visual Studio used custom regular expression syntax in the Find and Replace windows.
BillWoodruff wrote: how to select files that have specific text (keyword) content, and then apply S&R to only the matching files.
I don't think there's any way to do that in a single step, unless the content you're searching for is the content you want to replace.
You might need to do a "find in files" to find and open the matching files, and then a S&R targeting the open files.
Or were you wanting to limit the S&R based on the file names? I don't think they support regex; you'd need to use DOS-style wildcards instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, Richard,
My impression is that VS 2017 is using some form of JavaScript related regex syntax, which is still as non-standard as when Atwood made his comments in 2006. Of course, you can say it's .NET standard
It took me two days to figure out one multi-line RegEx solution in VS. The MSDN docs were (as so often) useless.
Thanks to Macej's extension ... which will generate a multi-line RegEx for you based on your selection in a code window ... this can be speeded up nicely.
The tricky part of my goal here is applying the S&R recursively to folders/files that contain the "keyword" ... but, applying only to open files may have to suffice.
It ought to be this simple:
Solution.Files.Search(SearchOption.Recursive)
.Where(file => file.Extension == ".cs")
.Select(file => file.StartsWith(@"//Keyword\r\n"))
.ReplaceInFiles(ReplaceOption.All)(@"stuff", @"newstuff);
Yes, that is wishful thinking
best, Bill
«Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.» Miss Piggy
|
|
|
|
|
BillWoodruff wrote: The tricky part of my goal here is applying the S&R recursively to folders/files that contain the "keyword" ... but, applying only to open files may have to suffice.
In VS, you can select files with a name pattern. In Find/replace dialog, define it in Look at these file types.
Moreover, you can select folders (and save this selection for later use) with [...] button next to Look in.
And you can apply the search to open documents only. Select All Open Documents in Look in.
|
|
|
|
|
Thanks, I am familiar with the uses of 'Find/Replace in Files you mention. But, what I am looking for is a way to apply a RegEx find/replace pattern recursively to files in nested folders with a keyword ... without having to open them all, or re-configure the current open code files in VS.
«Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.» Miss Piggy
|
|
|
|
|
BillWoodruff wrote: Solution.Files.Search(SearchOption.Recursive)
.Where(file => file.Extension == ".cs")
.Select(file => file.StartsWith(@"//Keyword\r\n"))
.ReplaceInFiles(ReplaceOption.All)(@"stuff", @"newstuff);
Yes, that is wishful thinking Simple. Write your own VS Add-In.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hi Ryan,
I'm curious ... have you written any VS extensions yourself that operated on open project files ?
A reasonable suggestion, but one I just don't have time to pursue. And, I can achieve what I want with UltraEdit. In my research on multi-line replacement, I came across a reference saying NotePad++ also has multi-line find.replace.
thanks, Bill
«Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.» Miss Piggy
|
|
|
|
|
Hi Friends.
i have more then 1 ComboBox to add items.
items are...
Makam
Sukam
Bhunte
Amma
Tantan
Toit
Hawa
Sanga
Jowan... so how to add these items same tiime in comboBox?
Pradeep Adhikari
|
|
|
|
|
|
Try:
string[] items = { "Makam", "Sukam", "Bhunte", "Amma", "Tantan", "Toit", "Hawa", "Sanga", "Jowan" };
myComboBox.Items.AddRange(items);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi, I am new to c# coding. The scenario for my problem is:
The outlook is hosted on a windows 2008 r2 server there are 12 mailboxes added in it, I want to fetch the details (like the sender name, when was the email recieved, the attachment name etc) of each emails recieved on each mailboxes everyday. The emails are in deleted folder of each mailbox. But there is a catch I dont have the password of any of the mailboxes, I need the extracted information in a CSV. Is it possible via C# if yes please guide then.
|
|
|
|
|
If you don't have the password, then what you are trying to do is wrong - and possibly illegal in some countries - you are authorized to access information via the username / password combo, and without both of those items you should not and cannot access the mails.
Contact the owners of the mailboxes and get their permission and passwords: then you should have no problem.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
So there is this guy called Member 13245972 who has an email account. I want to access his emails but I don't have his password, how can I do this.
Seriously? Exactly what kind of answer are you expecting to see?
|
|
|
|
|
it's working.
Thank you so much Richard MacCutchan.
|
|
|
|
|
Hello,
i am trying to analyze the issue of missing data over my Datagridview in C#.
I am receiving data from Serial port with 5250000 (5,25 Mbps)& Splitting it over datagridview (Datatable). Simultaneously i am saving this data over PC using Binarywriter.
However when i am analysing my dumped data file over pc, i found almost 30% of data is missing between two intervals. My timer Event is 1 milisec & i am updating datagridview in timer tick.
So how i can get contineous stream of data both over datagrid view & write it in file to save over PC?
Possible Error is use of Serialport.BytesToRead method as its blocking type.
SO can anybody tell where exactly i am wrong?
My Code is as below:
<pre>using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace DataGridView
{
public partial class DataGridView : Form
{
DataTable table = new DataTable("Sniffer Data Logger");
byte[] buffer = new byte[5 * 1024];
public DataGridView()
{
InitializeComponent();
table.Columns.Add("System Time");
table.Columns.Add("Source");
table.Columns.Add("T.S Begin");
table.Columns.Add("T.S End");
table.Columns.Add("Duration (uS)");
table.Columns.Add("Length");
table.Columns.Add("Data");
table.Columns.Add("CRC");
table.Columns.Add("CRC_PC");
serialPort1.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
this.BeginInvoke(new EventHandler(Timer1_Tick));
}
private string ByteArrayToHexString(byte[] data)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in data)
sb.Append(Convert.ToString(b, 16).PadLeft(2, '0').PadRight(3, ' '));
return sb.ToString().ToUpper().Replace(" ", "");
}
private void Timer1_Tick(object sender, EventArgs e)
{
int Bytes = serialPort1.BytesToRead;
byte[] buffer = new byte[5 * 1024];
long read = serialPort1.Read(buffer, 0, Bytes);
BinaryWriter writer = new BinaryWriter(File.Open("c:\\temp\\snifftimetick.dat", FileMode.Append));
writer.Write(buffer);
writer.Close();
if (read == buffer.Length)
{
byte[] newbuffer = new byte[buffer.Length * 2];
Array.Copy(buffer, newbuffer, buffer.Length);
newbuffer[read] = (byte)Bytes;
buffer = newbuffer;
read++;
}
}
DataRow row = table.NewRow();
if (ByteArrayToHexString(buffer).Contains("AA"))
{
if (ByteArrayToHexString(buffer).StartsWith("AA"))
{
switch (ByteArrayToHexString(buffer).Substring(6, 2))
{
case "11":
table.Rows.Add(row);
row["Source"] = string.Format("{0}", "ABUS_L/R");
row["System Time"] = DateTime.Now.ToString("HH:mm:ss:fff");
row["T.S Begin"] = ByteArrayToHexString(buffer).Substring(8, 8);
row["T.S End"] = ByteArrayToHexString(buffer).Substring(16, 8);
row["Length"] = ByteArrayToHexString(buffer).Substring(24, 2);
row["Data"] = ByteArrayToHexString(buffer).Substring(26, 2);
row["CRC"] = ByteArrayToHexString(buffer).Substring(28, 2);
row["CRC_PC"] = crc8.ComputeChecksum(buffer);
break;
case "12":
table.Rows.Add(row);
row["Source"] = string.Format("{0}", "ABUS_RK");
row["System Time"] = DateTime.Now.ToString("HH:mm:ss:fff");
row["T.S Begin"] = ByteArrayToHexString(buffer).Substring(8, 8);
row["T.S End"] = ByteArrayToHexString(buffer).Substring(16, 8);
row["Length"] = ByteArrayToHexString(buffer).Substring(24, 2);
row["Data"] = ByteArrayToHexString(buffer).Substring(26, 2);
row["CRC"] = ByteArrayToHexString(buffer).Substring(28, 2);
row["CRC_PC"] = crc8.ComputeChecksum(buffer);
break;
case "13":
table.Rows.Add(row);
row["Source"] = string.Format("{0}", "DataBus");
row["System Time"] = DateTime.Now.ToString("HH:mm:ss:ffffff");
string ts1 = ByteArrayToHexString(buffer).Substring(8, 8);
UInt32 number = Convert.ToUInt32(ts1, 16);
UInt32 time1 = swap(number);
double tmil1 = ((double)time1 / (double)1000);
string res1_tmil = tmil1.ToString();
string ts2 = ByteArrayToHexString(buffer).Substring(16, 8);
UInt32 number1 = Convert.ToUInt32(ts2, 16);
UInt32 time2 = swap(number1);
double tmil2 = ((double)time2 / (double)1000);
string res2_tmil = tmil2.ToString();
row["T.S Begin"] = time1;
row["T.S End"] = time2;
row["Duration (uS)"] = ((time2 - time1));
row["Length"] = ByteArrayToHexString(buffer).Substring(24, 2);
string len = ByteArrayToHexString(buffer).Substring(24, 2);
int count = int.Parse(len, System.Globalization.NumberStyles.HexNumber);
row["Data"] = ByteArrayToHexString(buffer).Substring(26, count * 2);
row["CRC"] = ByteArrayToHexString(buffer).Substring((26 + count * 2), 2);
row["CRC_PC"] = crc8.ComputeChecksum(buffer).ToString("X2").ToUpper();
break;
case "14":
table.Rows.Add(row);
row["Source"] = string.Format("{0}", "RESET");
row["System Time"] = DateTime.Now.ToString("HH:mm:ss:fff");
row["T.S Begin"] = ByteArrayToHexString(buffer).Substring(8, 8);
row["T.S End"] = ByteArrayToHexString(buffer).Substring(16, 8);
break;
default:
table.Rows.Add(row);
row["Source"] = string.Format("{0}", "ERROR_CMD_ID");
row["System Time"] = DateTime.Now.ToString("HH:mm:ss:fff");
int startIndex = 0;
string pattern = "AA";
string input = ByteArrayToHexString(buffer);
var regex = new Regex(pattern);
int endIndex = regex.Match(input, startIndex).Index;
int length = endIndex - startIndex;
row["Length"] = length;
break;
}
}
else if (!(ByteArrayToHexString(buffer).StartsWith("AA")))
{
table.Rows.Add(row);
row["Source"] = string.Format("{0}", "ERROR_PA_POS");
row["System Time"] = DateTime.Now.ToString("HH:mm:ss:fff");
int startIndex = 0;
string pattern = "AA";
string input = ByteArrayToHexString(buffer);
var regex = new Regex(pattern);
int endIndex = regex.Match(input, startIndex).Index;
int length = endIndex - startIndex;
row["Length"] = length;
}
}
else if (!(ByteArrayToHexString(buffer).Contains("AA")))
{
table.Rows.Add(row);
row["Source"] = string.Format("{0}", "ERROR_PA");
row["System Time"] = DateTime.Now.ToString("HH:mm:ss:fff");
}
dataGridView1.Update();
dataGridView1.DataSource = table;
}
public static UInt32 swap(UInt32 value)
{
return (value & 0x000000FFU) << 24 | (value & 0x0000FF00U) << 8 |
(value & 0x00FF0000U) >> 8 | (value & 0xFF000000U) >> 24;
}
public static class crc8
{
static byte[] table = new byte[256];
const byte poly = 0xd5;
public static byte ComputeChecksum(params byte[] bytes)
{
byte crc = 0;
if (bytes != null && bytes.Length > 0)
{
foreach (byte b in bytes)
{
crc = table[crc ^ b];
}
}
return crc;
}
static crc8()
{
for (int i = 0; i < 256; i++)
{
int temp = i;
for (int j = 0; j < 8; ++j)
{
if ((temp & 0x80) != 0)
{
temp = (temp << 1) ^ poly;
}
else
{
temp <<= 1;
}
}
table[i] = (byte)temp;
}
}
}
private void btnStart_Click(object sender, EventArgs e)
{
if (txtUser.Text.ToString().CompareTo("test") == 0 & txtPass.Text.ToString().CompareTo("test") == 0)
{
txtUser.PasswordChar = '*';
txtPass.PasswordChar = '*';
MessageBox.Show("Login Successfull", "Start", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (radioButton1.Checked == true)
{
serialPort1.Open();
label4.Visible = true;
label3.Visible = false;
label5.Visible = false;
timer1.Enabled = true;
}
else
{
MessageBox.Show("Choose Online Mode / Data Mode", "Start", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
label3.Visible = true;
MessageBox.Show("Wrong Username/Password! \n Please try again!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPass.Text = "";
txtUser.Text = "";
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
txtPass.PasswordChar = (char)0;
checkBox1.Text = "Show Password";
}
else
{
txtPass.PasswordChar = '*';
checkBox1.Text = "Hide password";
}
}
private void btnStop_Click(object sender, EventArgs e)
{
serialPort1.Close();
timer1.Enabled = false;
label3.Visible = true;
label4.Visible = false;
}
private void btnSave_Click(object sender, EventArgs e)
{
TextWriter writer = new StreamWriter(@"C:\temp\Sniffer_log.txt");
label5.Visible = true;
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
writer.Write("\t" + dataGridView1.Rows[i].Cells[j].Value.ToString() + "\t" + ";");
}
writer.WriteLine("");
}
writer.Close();
MessageBox.Show("Data Saved");
label5.Visible = false;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void btnclear_Click(object sender, EventArgs e)
{
table.Clear();
table.DefaultView.RowFilter = null;
}
private void button1_Click(object sender, EventArgs e)
{
table.DefaultView.RowFilter = "Length LIKE '*09*'";
dataGridView1.Refresh();
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
btnStart.Enabled = true;
btnLoad.Enabled = false;
}
private void btnLoad_Click(object sender, EventArgs e)
{
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
Using a timer is a bad idea. Data might get lost if there are more data send between two ticks than the internal buffer can hold (4096 bytes by default) and/or with high system load. The common method is using a thread that reads and processes incoming data (especially which high data rates like in your case). I suggest to use the BackgroundWorker Class (System.ComponentModel)[^].
However, the buffer size can be set with the SerialPort.ReadBufferSize Property (System.IO.Ports)[^].
If you still want to use a timer be aware that the smallest possible timer tick is system dependant (resolution of the system clock) which is used when passing a smaller value. The typical resolution is 15 ms.
There is also a possible buffer overflow in your code:
int Bytes = serialPort1.BytesToRead;
byte[] buffer = new byte[5 * 1024];
long read = serialPort1.Read(buffer, 0, Bytes); The commented line is doing it right.
|
|
|
|
|
Ok. One more Thing is about using Invoke method.
What i want to achieve is :
1. Read data on Serial port
2. Store it in File over PC (as raw data file)
3. Show data in decoded form over datagridview
So how i can invoke this 3 processes? If i solve this it will be done i guess.
I tried possibility like:
1. Read serialport data using serialport.BytetoRead();
2. Write data in File over PC
Both 1 & 2 i called in serialdataEvent handler
3. Invoke Timer from serialdataevent handler
But its giving me exeption handler error.
|
|
|
|
|