Subscribe: Custom Server Controls
Added By: Feedage Forager Feedage Grade B rated
Language: English
cells  edit  file  function  new  public shared  public  shared  string  style  system web  system  text  worksheet cells 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Custom Server Controls

All Forums

All Forums

Last Build Date: Wed, 24 May 2017 08:49:13 -0700


rt arrow keys and $(this)



I am working on a function for a menu.  The function handles tab, and right and left arrow keys.  The tabs work fine, but the right arrow keys don't work. After I first tab to the menu's first item, I can right arrow to the next item and it highlights the item. Then I set the focus on this item ( item.focus() ), but after I hit the right arrow key again, nothing happens, it just sits on the same item( unless I click on it then arrow to the next item).  When I look at $(this ) value right after I hit the right arrow key the first time, it is pointed to the next element.   Am I supposed to set a variable so that I can set the active menu item manually?     thanks.

Read data from an USB card reader (client side)



I have to read data from an USB card reader that is configured as a virtual COM port on the user pc.
Of course I know that a web page can't access client local resources, I tried "server side" (on my developing pc) and I can read data from the reader without problems but how client side?
An ActiveX?
ActiveX only works with IE but I would like to develop something that is not related with a specific browser.
Another way different from using ActiveX?
Thanks, best regards.


Get Docker container ID in code


I have the need to log the container ID my app is running in. Is there a way to get this via C#?

Returning joined tables using MVC



I am attempting to join two tables using the code below in my controller:

    public JsonResult GetProductDropDown()

            fitzEntities context = null;

            context = new fitzEntities();

            context.Configuration.ProxyCreationEnabled = false;

            var products = from c in context.products join sa in context.stores on c.store_id equals sa.store_id select;

            return Json(products, JsonRequestBehavior.AllowGet);

What I want to do is then add the data from the two joined tables to an array using JSON. I have attempted to do this using the code below and can return data from the products table using this.field_name but can't figure out how to return data from the stores table (I have tried this.store_name and Could anyone assist please?

  $(document).ready(function () {

        var options = [];

        $.getJSON("/CustomerOrders/GetProductDropDown", null, function (data) {
            $.each(data, function () {
                if (this.display_stock == true) {
                    if (this.product_quantity <= 0) {
                        options.push(this.product_name + ", £" + parseFloat(this.product_price, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString() + ", Display stock at store " + this.store_name + ", OUT OF STOCK - SUPPLIER ORDER REQUIRED");


String not recognised as a valid Datetime



The below code creates a Calendar, which I am using to select a date and time:

When, I run this code, I use a calendar to select a date and a time.

After selecting these, the date & time populate a textbox like so: 24/05/2010 16:21

But, when I try to store the value in this textbox in a datetime column in my SQL Server database, I get the following error:

"String was not recognised as a valid Datetime"

Below is my C#:

    private void addShift(string start_Time, string end_Time, string job_Type, int employee_ID)
        conn = new SqlConnection(connectionString);
        string sql = "INSERT INTO Shift VALUES(@start_Time, @end_Time, @job_Type, @employee_ID)";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@start_Time", Convert.ToDateTime(start_Time));
            cmd.Parameters.AddWithValue("@end_Time", Convert.ToDateTime(end_Time));
            cmd.Parameters.AddWithValue("@job_Type", job_Type);
            cmd.Parameters.AddWithValue("@employee_ID", employee_ID);
            cmd.CommandType = CommandType.Text;
        catch (Exception ex)
            lblError.Text = ex.Message.ToString();

SignalR version 1.2.2 getting Error: The controller for path '/function () { _pageLoaded = true; }' was not found or does not implement IController


I am using SignalR version 1.2.2 with ASP.NET MVC 4. I set the signalR connections to a page inside a defined "Area" Regardless though, this seems to come at the SignalR script load. Because if I access a view defined in the main area outside of the areas sections, I still get this error:

System.Web.HttpException (0x80004005): The controller for path '/function () { _pageLoaded = true; }' was not found or does not implement IController. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I found,

/function () { _pageLoaded = true; }
inside jquery.signalR-1.2.2 as
_pageWindow.load(function () { _pageLoaded = true; });

I have followed this tutorial: Tutorial which uses a singleton to maintain a instance of the Context for the hub. what could I be doing wrong?

Update: when I remove the script reference to the SignalR js file from the head the error goes away, so I can confidently say it is SignalR related.

How to modify New Site: <%: Context.User.Identity.GetUserName() %>


I have created from VS2017 ASP.Net simple site with login.

In master page there is a line

Hello, <%: Context.User.Identity.GetUserName()  %>

It is displaying the user email instead of his name.

I stored the friendly user name in another table: [RealName].[FriendlyName].

How to modify the above code to display the FriendlyName above ?

Thanks a lot.

remove quotes from within string


I want to replace 




I've tried


but it fails, am I missing a quote somewhere?

In Edit View for DropDownListForm selcteditem is not working


Hi there,

When I click on Edit link and edit view is displayed, the dropdownlist is populated but selected item is not set to what it is in the model. Any idea what is causing this?

Here is my view

@Html.LabelFor(model => model.Gender, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.DropDownListFor(model => model.Gender, ViewBag.Gender as List, new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.Gender, "", new { @class = "text-danger" })

Here is my Edit action from controller

        // GET: tests/Edit/5
        public ActionResult Edit(Guid? id)
            //populate Gender dropdown
            List gen= new List();
            gen.Add(new SelectListItem { Text = "-- Please Select --", Value = "" });
            gen.Add(new SelectListItem { Text = "Male", Value = "Male" });
            gen.Add(new SelectListItem { Text = "Female", Value = "Female" });

            ViewBag.Gender= gen;

            if (id == null)
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            test t1= db.tests.Find(id);
            if (t1== null)
                return HttpNotFound();

            return View(t1);

I see all the other deftails fetched from database for given id, even the Gender dropdown is populated but if Female is the selected value in database then it is not displayed in Edit view as selected.



Checkbox value changes after executing store procedure


I've got a new interface feature that I've built on top of the standard asp:GridView control.  The only modification that I've made to the GridView as it renders out of the box is to add an 'unbound' asp:TemplateField that holds an asp:CheckBox control. The purpose of this checkbox column is to provide a means for the user to select multiple rows that can then be referenced in the code behind to affect change on those rows via a stored procedure in the SQL database related to the app.  Once the user selects two or more rows with the CheckBoxes they would select one of four columns to focus on from a DropDownList located outside of the GridView then click on an 'Edit Selection' button. The click event with the button then verifies that there are at least two checkboxes marked and that a column is chosen. I then populates three values and places them into a asp:Panel which is kept hidden until the button has been clicked.  This panel displays all the rows checked along with an TextBox populated with the value from the first row checked (only as reference to the user of what is there presently) and allows the user to make alterations to the TextBox which are then fed row by row to the stored procedure which writes the new value in the column that the user has selected. Effectively completing a 'multi row - column edit'. This function is working perfectly up to the point of completing the first update to the database. What has me stumped for the moment is that when the 'Edit Selected' button is clicked the second time (for the same column or a different one doesn't matter)  the debug shows that: if (((CheckBox)grv.FindControl("TagRowChkBx")).Checked == true) ... which was true the first pass through before executing the stored procedure. Now is no longer true and as a result the panel to edit the column remains hidden, unpopulated; bypassing the store procedure (which wouldn't be executed until the 'Save' button on the edit panel was clicked). Doing a refresh doesn't restore the function nor anything else I can try with the web app. I have to close the browser (ending debug) and restart to do another column edit. I can't find what is causing it or how to correct it. Here is the a fragment from the definition of the GridView: <%-- 13 addtional BoundFields --> Here is the code behind fragment that is misbehaving (I've noted the line where the 'true' becomes untrue or the second pass with a comment): protected void EditSelctedBtn_Click(object sender, EventArgs e) { //Read the column select drop down List into Local Varriables String SelectedColumnItem = ColumnSelectDDL.SelectedItem.ToString(); String SelectedColumnValue = ColumnSelectDDL.Selected[...]

A Function inside App_Code Class is not callable


I created a class "TDClass.vb" inside App_Code folder. The "TDClass.vb" class is as following Imports Microsoft.VisualBasic Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Imports System.Diagnostics Imports System.Drawing.Printing Imports System.Windows.Forms Imports System.Collections.Generic Imports Microsoft.Office.Interop Imports System.IO.File Imports Neodynamic.SDK.Web Public Class TDClass Public Shared UserName As String Public Shared UserIndx As Integer Public Shared PassCode As String Public Shared UserUnitIndx As Integer Public Shared SelectedOffice As String Public Shared ShownOffices As New Stack Public Shared ReportingToStack As New Stack Public Shared HeadOffices As New Stack Public Shared PendingCommentsRemarkerHeadsStack As New Stack Public Shared queryString As String Public Shared PreviousFormPath As String Public Shared TheSameLevelUnits As SqlDataReader Public Shared LIDCount As Integer Public Shared Initiator As Integer Public Shared DataEntryRight As Integer Public Shared DataEntryRightB As Integer I added the following function "GetExternalParameters" inside the "TDClass.vb" class: Public Shared Function GetExternalParameters(ByVal UnitIndex As Long, ByVal Purpose As String) As String Dim querystring As String Dim EntityName As String Dim EntityTitle As String Dim EntityCPR As String GetExternalParameters = "" Dim conString = ConfigurationManager.ConnectionStrings("TrackingConnectionString").ConnectionString Using connection As New SqlConnection(conString) connection.Open() If Purpose = "entity" Then querystring = "SELECT Entity FROM ExternalEntities WHERE (Indx=@Ix)" Dim ExtractEntityName As New SqlCommand(querystring, connection) ExtractEntityName.Parameters.Add("@Ix", SqlDbType.Int) ExtractEntityName.Parameters("@Ix").Value = UnitIndex If IsDBNull(ExtractEntityName.ExecuteScalar()) = False Then EntityName = ExtractEntityName.ExecuteScalar() GetExternalParameters = EntityName End If ElseIf Purpose = "title" Then querystring = "SELECT Title FROM ExternalEntities WHERE (Indx=@Ix)" Dim ExtractTitle As New SqlCommand(querystring, connection) ExtractTitle.Parameters.Add("@Ix", SqlDbType.Int) ExtractTitle.Parameters("@Ix").Value = UnitIndex If IsDBNull(ExtractTitle.ExecuteScalar()) = False Then EntityTitle = ExtractTitle.ExecuteScalar() GetExternalParameters = EntityTitle End If ElseIf Purpose = "cpr" Then querystring = "SELECT CPR FROM ExternalEntities WHERE (Indx=@Ix)" Dim ExtractCPR As New SqlCommand(querystring, connection) ExtractCPR.Parameters.Add("@Ix", SqlDbType.Int) ExtractCPR.Parameters("@Ix").Value = UnitIndex If IsDBNull(ExtractCPR.ExecuteScalar()) = False Then EntityCPR = ExtractCPR.ExecuteScalar() GetExternalParameters = EntityCPR End If End If End Using End Function I have form "ShowPostingDetails_ExFrom.aspx". It contains a textbox "FormExternalEntityNameTxtBox". I call the "GetExternalParameters" function from the form as follow: Dim EntityName As String EntityName = TDCla[...]

Browser does not display correct language after copy pasting text into view


in my app I pasted in some example code from bootstrap. then i changed some text which uses letters that are not in the english alphabet. But the letters aren't displayed correctly on this page. It works on all my other pages. I tried to change the language spec in my html like this:

but that does not solve my issue.

any ideas?

Resize Div Elements when Page Size is Changed


How do I modify the following code so the DIV elements will resize when page is resized? I want it to take the entire page.

Click not executed after autocomplete item selected


I have a page with a form and an update panel. On the update panel there is textbox that has an autocompleteextender. After I select an item in the textbox no click on the page works. I can not use the select fields, the buttons in the grid or links. However if I click anywhere on a control that does not have a click associated the page "recovers" and the clicks are again functional.

How can I figure out what is the problem?

MVC 3: @Html.RadioButton within @foreach


Hi, I am new to MVC and am hoping someone can please assist.

In my model I have an int column that has a value of 1 or 2 (public int radiobutton { get; set; }).

My view returns more than one record.

@foreach (var item in Model)

@Html.RadioButtonFor(model => item.radiobutton, 1, new { name = "radiobutton1_" + })one
@Html.RadioButtonFor(model => item.radiobutton, 2, new { name = "radiobutton1_" + })two


There are two problems:

1. The value is not setting the RadioButton on each row

2. The RadioButton is across all of the rows instead of each row in that selecting a radio button on one row changes the selection across all of the other rows

I need to view attachment file into iframe using C# web form


Dear ALL

My client want attachment file should be open in iframe, means he dont want to download attachment file when he will click on attachment button..  always it should be viewable, I need to view attachment file into iframe or other method, file extention will be multiple format images format, pdf format or doc formation, if this is not possible means please give pdf file should viewable.

I am binding into link button  and dt.Rows[0]["Plan"].ToString(); is the file name.


  lnkbtn_Plan_update.Text = dt.Rows[0]["Plan"].ToString();

Export xlsx in ASP.NET Core - cannot open a file.


I'm trying to export XLSX file in ASP.NET Core using EPPlus.Core library.

Here's my code: from controller:

byte[] bytes;

MemoryStream stream = new MemoryStream();
using (ExcelPackage package = new ExcelPackage(stream))
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Employee");
//First add the headers
worksheet.Cells[1, 1].Value = "ID";
worksheet.Cells[1, 2].Value = "Name";
worksheet.Cells[1, 3].Value = "Gender";
worksheet.Cells[1, 4].Value = "Salary (in $)";

//Add values
worksheet.Cells["A2"].Value = 1000;
worksheet.Cells["B2"].Value = "Jon";
worksheet.Cells["C2"].Value = "M";
worksheet.Cells["D2"].Value = 5000;

worksheet.Cells["A3"].Value = 1001;
worksheet.Cells["B3"].Value = "Graham";
worksheet.Cells["C3"].Value = "M";
worksheet.Cells["D3"].Value = 10000;

worksheet.Cells["A4"].Value = 1002;
worksheet.Cells["B4"].Value = "Jenny";
worksheet.Cells["C4"].Value = "F";
worksheet.Cells["D4"].Value = 5000;
bytes = package.GetAsByteArray();

return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "test");

It was successfully exported a file but there is an error message when I try to open a file using Microsoft Excel I'm getting an error message:

"We found a problem with some content in 'text.xslx'. Do you want to
us to try to recover as much as we can? If you trust the source of
this workbook, click Yes."

and after I click "Yes" button, I'm getting an error message:

"Excel cannot open the file "test.xslx", because the file format or
file extension is not valid. Verify that the file has not been
corrupted and that the file extension matches the format of the file.

Do you have any idea how can I solve this problem?

How to return a result with HttpStatusCode in Web API


I have a post method below, How to retunr the result with Status Code?

public HttpResponseMessage createQuesFailCodeByLangCat([FromBody] QuestionsFailCode questionsFailCode) //
string result = String.Empty;
result = "execute something, then get results such a UserID"

catch (Exception ex)
string message = ex.Message;
return new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
return new HttpResponseMessage(HttpStatusCode.Created, result );


Displaying data / content in a popup window


I'm needing to show contents from an Edit.cshml page in my mvc app via a popup window. When I select a reccord to edit, i want to also view the contents of the record in a popup. The field (i'll call if myField) shows its content in a textarea, then when the user clicks the Preview button, the data will show in the popwindow. 

public string OpenPreview()
return ViewBag.myField;


So putting this function in the myhomecontroller code, ViewBag does not render the display in the popup window, just blank. So I'm wondering what method here i can use in my return statement of the OpenPreview function

Thanks for all help