ASP.NET

125K

Solutions

28K

Contributors

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

Share tech news, updates, or what's on your mind.

Sign up to Post

IF I didn't put any value in date text box it make an exception
How to allow null value (Nullable) in this code


DateTime datelift = DateTime.ParseExact(txt_lift.Text, "yyyy-MM-dd", null);   
SqlCommand lift = new SqlCommand();
lift.CommandText = "insert into table1  (date) values ('" + datelift.ToString("yyyy-MM-dd") + "')";

Open in new window

0
Hi

I'm using npgsql for first time with postgres 11 db

My code is as follows

    cmd = new NpgsqlCommand("INSERT INTO \"tracking_dataa\"(imei_number, gps_datetime, event_id, speed, latitude, longitude, heading, raw_data)	" +
                                                                          "VALUES(@ImeiNumber, @GPSDateTime, @EventId, @Speed, @Latitude, @Longitude, @Heading, @RawData);", con, transactSql)
                                {
                                    CommandType = CommandType.Text
                                };
                                cmd.Parameters.AddWithValue("@ImeiNumber", item.ImeiNumber);
                                cmd.Parameters.AddWithValue("@GPSDateTime", item.GPSDateTime);
                                cmd.Parameters.AddWithValue("@EventId", item.EventId);
                                cmd.Parameters.AddWithValue("@Speed", item.Speed);
                                cmd.Parameters.AddWithValue("@Latitude", item.Latitude);
                                cmd.Parameters.AddWithValue("@Longitude", item.Longitude);
                                cmd.Parameters.AddWithValue("@Heading", item.Heading);
                                cmd.Parameters.AddWithValue("@RawData", item.RawData);
                            
                                cmd.ExecuteNonQuery();

Open in new window


However, I get the error
{"42P01: relation \"tracking_dataa\" does not exist"}

Open in new window


i've tried the following

INSERT INTO \"tracking_dataa\"(imei_number, gps_datetime, event_id, speed, latitude, longitude, heading, raw_data

INSERT INTO tracking_dataa (imei_number, gps_datetime, event_id, speed, latitude, longitude, heading, raw_data

INSERT INTO \"public\".\"tracking_dataa\"(imei_number, gps_datetime, event_id, speed, latitude, longitude, heading, raw_data

INSERT INTO public.tracking_dataa (imei_number, gps_datetime, event_id, speed, latitude, longitude, heading, raw_data

Open in new window


Nothing seems to work, the same error exists

When I browse my DB in Navicat, the table is under the public schema and I can connect fine

What am i doing wrong?
0
this my error and my code

i have a problem with data fill in database

error is
Conversion failed when converting date and/or time from character string

my data type is date
i put data from text box mode date

Image-1.png
0
How can I make my database allow Arabic language character in sql server
0
Hi experts,
I have wrote the C# API programe to get data from different location.
All used to work fine.Suddenly it's generating error becuase the records not available
in the API records.(requesting records)There is no way to find Candidate avaiable or not.

see below link how the API request send.

https://test/v3/company/18f62e940d1d01/position/771b0f2aff3c01/candidate/05ea659e456a01/stream

Error:

 500 Internal Server Error
{
    "error": {
        "type": "getStreamError",
        "message": "there was an unknown error getting candidate stream."
    }
}

 string urlCandatestream = "/company/" + CompanyID + "/position/" + positionID + "/candidate/" + candidateID + "/stream";
                var request = new RestRequest(urlCandatestream, Method.GET);


                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("authorization", connectAPI.getAccessToken());
                // rqst.Proxy = GlobalProxySelection.GetEmptyWebProxy();

                IRestResponse response;
                varRequest = request.ToString();
                try
                {
                    response = await _restClent.ExecuteTaskAsync(request);
                    VarRequestResults = response.Content;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error executing  request to " + 

Open in new window

0
Hi

I want to use ASP.net to build a web app for gathering simple data plus images on mobile phones. My client has stipulated that the system be available when offline. How would I do this? Can ASP.net even be used for this?

Thanks
0
I am trying to pass a value to a datetime value from a database.  Unfortunately, the my code doesn't exactly like the format.  I get the following error:  

String was not recognized as a valid datetime.

this my c# code

<code>

TextBox reffd = GridView1.Rows[e.RowIndex].FindControl("txt_RefD") as TextBox;
TextBox outd = GridView1.Rows[e.RowIndex].FindControl("txt_Outd") as TextBox;


</code>

and this my sql command

<code>
SqlCommand cmd = new SqlCommand("Update FZMain set Name='" + name.Text + "',Payment = '" + pay.Text + "', Cases = '" + cases.Text + "',  Reffrence = '" + reff.Text + "',ReffrenceDate = " + DateTime.ParseExact(reffd.Text, "dd-mm-yyyy", null).AddHours(-5) + "), OutDate = " + DateTime.ParseExact(outd.Text, "dd-mm-yyyy ", null).AddHours(-5) + "), FamilyRegister = '" + femreg.Text + "',LastOwner='" + lastO.Text + "', ChassisNO='" + Chasses.Text + "', CarModel='" + CarModel.Text + "' where ID=" + Convert.ToInt32(id.Text), con);

</code>

data type in database is date
0
Hello All,

I tried to create an ASP.NET MVC CORE web project using Visual Studio 2019 Community. But when I am right-clicking on Model Folder >> Add A New Item>>
I am seeing “ADO.NET Entity Data Model” under [Data] tab. Can someone explain what I need to do so that I can see “ADO.NET Entity Data Model” under [Data]  ?

Thank you
ADO-NET-Entity-Data-Model.docx
0
Why do some of my .aspx pages add this to the URL? (ex. www.url.com/filename.aspx?_ga=2.176514797.910954863.1579199334-2140930447.1563381308

I don't know why it adds ?_ga=2.176514797.910954863.1579199334-2140930447.1563381308 to the end of the URL when I bring the file up in the browser. Is that something that I'm doing wrong?
0
I need to understand how to cast a complex deserialized  Json object to enumerable so that it can be bound to an a gridview

           var enumerable = new[] { GetBuilds().Result};
                       

            GridView1.DataSource = enumerable;
            GridView1.DataBind();

Open in new window




2020-01-13_11-28-21.png


Currently it only results in the top node, i need to get the data in the fields node.

2020-01-13_11-29-37.png
0
Hello Experts,

I have a textbox(input) when user enter accept only numbers(digits only) and it should be 10. Once entered we need for format like (123)456-7890. I tried below but not working as expected.
CSHTML
 <input type="text" id="PhoneNumber" name="PhoneNumber" value="" class="form-control" autofocus="autofocus" maxlength="11">
                                <span class="bar" id="ErrMsg" ></span>
                                <label for="PhoneNumber">Phone</label>

Open in new window


JS
$("#PhoneNumber").keypress(function (e) {
    //if the letter is not digit then display error and don't type anything
    if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        //display error message
        $("#ErrMsg").html("Digits Only").show();
        return false;
    }
});

$("#PhoneNumber").blur(function (e) {
    phone = $(this).val();
    if (phone.length != 10) {
        $("#ErrMsg").html("Phone number must be 10 digits.").show().fadeOut("slow");
        return false;
    }
    else
        $(this).val($(this).val().replace(/^(\d{3})(\d{3})(\d)+$/, "($1)$2-$3"));
});

Open in new window


I have couple of issues with the above code, first I did Maxlength 11 then only it's accepting 10 digits and also I get format like this (123)456-0 (since my maxlenght was 11). After changing Maxlength to 14, I still get same issue. Please suggest how can I solve this.

Thanks,
ASPDEV
0
Coding in ASP.NET and C#

Hello Experts,
I am trying to run a Windows Service job only once everyday at a time specified in App.Config file.  How can I use make use of Timer class?  As soon as the job is done, the job will go to sleep mode and again wake up next day.  Is there a simple way?

Here is the requirement.

 1. Process Schedule Task
    Add code to Process the task here
    .
    .

 2. Once the job is executed, reset next run to every 24 hours

Thank you very much in advance!
0
This question needs a little explanation and background

I have  C# asp.net code that talks to a database and I have javascript on the client end. Javascript makes async calls to the backend c# code via a post and waits for results back. On the client code there is a list of items which get altered based on what the backend page returns.

Currently, when I do any db operation, I then query the db again to get the values of all items on the list and return them back to the client. So any addition, update, deletion...causes me to query the db again and return all items rather than just the one that was altered. This assures that the database and what is on the client list is always the same. But this is inefficient for the db to have that second query.

I'm thinking about simply checking for any errors from the db and then just returning a success or fail and then the javascript can update the list based on values it already had from the submission form.

Is there any way that I could KNOW that the db operation definitely succeeded and there is no chance the db will have different data than the client without having to re-query the db again?
0
Hi in my ASP.net web app my hosting provider Hostgator said they did the following. I am not sure which lines they are referring to in my web.config file shown further on

Hosrgator's comment: "Finally I commented out the system.codedom section of lines 35-40, as that section is not allowed on shared servers, due to the security implications of allowing custom compilers.  Once all of this was done the site started to load properly."

my web.config file:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <!--
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.6.1" />
      </system.Web>
  -->
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.6.1"/>
    <httpRuntime targetFramework="4.6.1"/>
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization"/>
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
      </controls>
    </pages>
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        …
0
Hi,
I have already done some webform development, however I am thinking of developing a new project and I think it makes no sense to use a technology that I think is becoming obsolete.
As I usually develop in .NET I thought about using Blazor, since I don't have many skills in java framework either.
It makes sense to choose blazor, or it would be better to choose asp.net core controls or another java framework. Will blazor succeed?

best regards
1
Hi
How do I display a GIF file on an ASP.net web form?
Thanks
0
Hello Experts,
I have a Console App, which imports some data thru an API call.  In this all the methods are defined inside the Main().  I am trying to define some methods such as xxxSearch and XxxxDetail, return type List, outside of the Main() method.  When I do that, I am getting the Error: CS0120 An object reference is required for the non-static field, method, or property 'XxxxImport.XxxxSearch(DateTime, DateTime)'.

The reason I need to do this, because I need to convert this to a Windows Service Program comfortably.

Please let me know how to define them outside of Main() method and call them,

Thank you very much in advance.

Below is the Skeleton of the Code
----------------------------------------------------

public static void Main(string[] args)
{
    DataSet ds = new DataSet();

    var fromDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")).AddDays(-1);
    var toDate = DateTime.Parse(fromDate.ToString("yyyy-MM-dd")).AddDays(0);

    MainHub(fromDate, fromDate);

    Environment.Exit(0);


    void MainHub(DateTime FromDate, DateTime ToDate)
    {
      var xxxFound = xxxSearch(FromDate, ToDate);

      if (xxxFound != null)
      {
          InsertxxxRaw(xxxFound, FromDate);
      }

      foreach (var xxx in xxxFound)
      {
          var list = new List<string>();
          list.Add(xxx.xxxNumber);

          var details = xxxDetail(xxx.validatingxxxDesignator, list);

          if (details != null)
          {
            …
0
Is there a way to display the value of MyClass.SomeMessage in the expression builder <%$  $> of the Label control below?

<asp:Label ID="lblMessage" runat="server" Text="<%$ Is there a way to display the value of MyClass.SomeMessage here %>" />

    // This class is defined in App_Code folder
    public static class MyClass
    {
        public static string SomeMessage
        {
            get
            {
                string message = "This is some test message";
                return message;
            }
        }
    }
0
Hi

I have only built ASP.net we solutions with cloud based sql databases. I have been asked to build a solution on a company server with  local SQL database.  Where would I publish my web app to?
I am only used to publishing web apps to Azure or a web hosting provider's folders
0
I just want to open / download excel sheet using vb.net
it works but it shows blank excel. The excel file actually have data inside.
Can you help how to fix it?

 Dim ExportFileName = "C:\Reports\activemember.xls"
        HttpContext.Current.Response.Clear()
        HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", ExportFileName))
        HttpContext.Current.Response.ContentType = "application/ms-excel"
        HttpContext.Current.Response.End()

Open in new window

0
what are the Steps to set up the web server (IIS, Apache)
0
I keep getting the Exception: System.ArgumentNullException: Value cannot be null. Parameter name: value.. every time I log into my ASP.NET MVC 5 Web Site with Entity Framework 6. My stack trace shows:
at System.Security.Claims.Claim..ctor(String type, String value, String valueType, String issuer, String originalIssuer, ClaimsIdentity subject, String propertyKey, String propertyValue)
   at System.Security.Claims.Claim..ctor(String type, String value)
   at Microsoft.AspNet.Identity.ClaimsIdentityFactory`2.<CreateAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at CastingAbout.Models.User.<GenerateUserIdentityAsync>d__225.MoveNext() in \\10.210.0.12\Sites\www\mysite.com\Models\User.cs:line 324
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNet.Identity.Owin.SignInManager`2.<SignInAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at …
0
Hello,

How can I transfer data from the dialog box to the parent window?

I need your help.

I have a parent window and a popup window

1. user open popup window
2. the popup window has a textarea
3. the values that are in the textarea needs to go back to the parent textarea.

I don't know what I'm doing wrong.

Text area in the parent window: 

 @Html.TextArea("ConditionAttributesAndValues", new { @class = "form-control", @style = "width:77%" })

My dialog box in the parent window:

$(function () {
            $('#dialog').dialog({
                autoOpen: false,
                width: 950,
                height:650,
                resizable: true,
                title: 'Condition',
                modal: true,
                open: function(event, ui) {
                    $(this).load("@Url.Action("RulePartialView", "CareAdvanceBusinessRules")")
                    $(".ui-dialog-titlebar-close").hide();
                },
                buttons: {
                    "Close": function () {
                        $(this).dialog("close");
                    }
                },
                closeOnEscape: false,
            });
            $("#opener").click(function (event) {
                event.preventDefault(); 
                $("#dialog").dialog("open");
            });
        });

Open in new window


This is what I have in the dialog box: 

// Here where I need the help 
// I want what ever I have in the textarea to be sent to the parent textarea. 

     $("#AppendConditionToParentBtn").click(function () {
            $('#ContidionsAndAttributesTextArea').text(window.opener.$("#ConditionAttributesAndValues").val());
            $('#dialog').dialog('close');
            return true;
        });

 <button id="AppendConditionToParentBtn" name="AppendConditionToParentBtn" class="btn btn-default" type="button" style="margin-top:10px;margin-bottom:10px;" value="Append">
                        Submit 
                    </button>

Open in new window


I'm getting this error

Unhandled exception at line 513, column 13 in eval code

0x800a138f - JavaScript runtime error: Unable to get property '$' of undefined or null reference
0
I am using a NoUISlider in asp.net and want to know how to retrieve the values for the slider. It is a multi-slider, so needs to return the left and right sides.
slider
From what I've determined by reading, I will attach a javascript method to the save button.
btnSave.Attributes.Add("onClick", "SaveSlider();return true;")

Open in new window


Then the javascript will store the values to two hidden elements and I'll use those server side.

Code would look something like this:

    function SaveSlider() {

        var slider = document.getElementById('slider-tooltips');
        var values = slider.noUiSlider.get();

      //  var values = $('#exampleSlider0').noUiSlider('value');

        document.getElementById("hdnSlider1").value = values(0);
        document.getElementById("hdnSlider2").value = values(1);
    }

Open in new window


I read that it retrieves the values as an array.

How do I retrieve and store the values to the hidden fields?

Also, any suggestions for populating the values on page load with existing values?

Anyone have an existing method?

thanks!
0
My web site has an web application in a subdirectory. I created first a virtual directory for it, then "convert to application". Both the site and the app share the same pool.

As long as I call a page of the app (a .aspx) directly through browser address, it works just fine. In addition, the app pages have non-restricted access to the hosting site's files.

But if I call such a page from a .htm page on the site (a non-app page), ASP.NET Event 1310, Event Code 3006, and in the Request information section, User: Is authenticated: False.

My guess was the account IIS uses to access a .aspx page directly is different from the account the web site uses to call such a page from one its own .htm pages.

How can I fix this? (no experience with such issues) Server is 2019.
0

ASP.NET

125K

Solutions

28K

Contributors

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications