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

convert .aspx to .doc maintain header footer positions
0
Hi

I am busy creating a new Azure web app and it is asking me to select a runtime stack.
My ASP.net project is built in the 4.6.1 framework so I am not sure if I should select 4.7
from that list. What is a runtime stack?

1
0
ASP.net textbox onblur JS function... Need to grab textbox ID and send it to function rather than hardcode the ID in the param pass for each input object

So have this and it works with hard code name of textbox id...

onblur="CheckEnteredDate(this,'CBirthDate_1');"

would i use <%  %> ??

for this function..

function CheckEnteredDate(passed, myID) {
        //alert("This is my input value = " + myID);
        if (new Date(passed.value) > new Date()) {
            alert('STOP - The Birth Date You Entered Is Greater Than Today!');
            document.getElementById(myID).value = "";
            return false;
        }
    }

Open in new window

0
Greetings:

I am converting VB.NET code to c# for ASP.NET web page code behind. I am learning c#.

Below is the aspx page, the aspx code behind and the invoked class method.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestIt.aspx.cs" Inherits="TestIt" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
</head>
<body>
	<form id="form1" runat="server">
		<asp:Label ID="lblString" runat="server" Text="Some string"></asp:Label>
	</form>
</body>
</html>

Open in new window

using BaBUtilityCSharp;
using System;

public partial class TestIt : System.Web.UI.Page
{
	protected StringMassage sm = new StringMassage();

	protected void Page_Load(object sender, EventArgs e)
	{
		lblString.Text = sm.HtmlLineBreak(lblString.Text) +
						 " More string";
	}

}

Open in new window

		public string HtmlLineBreak(ref string strData)
		{
			if (strData.Length > 0)
				return strData + "<br />";

			return strData;
		}

Open in new window

I'm receiving a syntax error within Visual Studio Pro 2019 as follows.
 Error passing the text property of a web control to a class method
What is the correct c# syntax to pass a web control's text property to a class method please?

Much thanks,
David Bach
0
ASP.net  TextBox Mode Property set to Date... TextMode="Date" Allows user to pick a date from a built in Date picker or TYPE A DATE into the textbox mm/dd/yyyy  (works great if the user types in a correct date format for year

Try out typing in 555555 or similar number of year !  www.enflow.com/CC/P1/EE.aspx

But the user can type in a year of 555555 or similar which will cause a SQL insert Truncate error on submit...

How do i format this TextMode property to ONLY allow 8 numbers (Two slashes are default) on page load attribute setting ???

thanks.. CJ

<%@ Page Language="VB" AutoEventWireup="false" Debug="true" MaintainScrollPositionOnPostback="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.UI.Page" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.data.OleDb" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Register Assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="System.Web.UI.WebControls" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Page.EnableViewState = false
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-us">
<head>
    <title>CC Housing 

Open in new window

0
I am a C# programmer. I'd like to start learning ASP.NET, but before that I'd have a couple of questions:

1. Should I learn ASP,NET Core or ASP.NET MVC? (What I need is to dynamically reformat pages on an existing web, at request, and also to provide user feedback forms that should access a database.)

2. I have on location an old Windows Server 2003 and another 2008, which I thought of using for testing samples. Can the framework required by ASP.NET Core be installed on such older servers? Would older IIS handle the job?

3. This book "ASP.NET Core in Action" is recent but some readers complain it's too verbose. Would you recommend another book/tutorial?
0
Hi,

Hi, I am using this online solution for Grideview Drag and Drop asp.net web forms (https://www.aspsnippets.com/Articles/Reorder-GridView-Rows-Drag-and-Drop-ordering-of-GridView-Rows-using-jQuery-in-ASPNet.aspx).  Everything works fine but now I need help updating the database table with additional fields.  For example:  I need to update the table of who dragged and dropped the row.  I added the "UpdateBy" field to my update statement , it works, but it updates every row with the value not the one row that was dropped.  What am i missing? Please need help asap.

  

  Private Sub BindGrid()
        Dim query As String = "SELECT [id], [DisplayOrder], [STUDY], [PATIENT],[WAIT_TIME],[USER_ID],[UpdateBy] FROM [Radio_queue4] " +
"order by DisplayOrder asc"
        Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand(query)
                Using sda As New SqlDataAdapter()
                    cmd.CommandType = CommandType.Text
                    cmd.Connection = con
                    sda.SelectCommand = cmd
                    Using dt As New DataTable()
                        sda.Fill(dt)
                        grid.DataSource = dt
                        grid.DataBind()
                    End Using
                End Using
            End Using
        End Using
    End Sub

 Protected Sub UpdatePreference(sender As Object, e As 

Open in new window

0
I have an angularjs app, that makes calls to asp.net web api.
I am new to both, but inherited the project from someone else

once logged into angular app, after some time, I get "502 Bad Gateway" error, when i try to refresh the page.
I'm guessing may be there is a session timeout duration set somewhere, where the sessions times out and I'm logged out and when I try to do something on the site, it gives me 502 Bad Gateway error.

I am trying to find out how can I catch this exception where possible so that I can let users know that they need to log back in or some useful warning.

the angularjs app had a backend web api service that it talks. where would this happen , in the api or in the anuglar front end code?
0
Hi. I am using the following VB.net code in ASP.net to create authenticate the user and then
create an invoice. The authentication works but then there is a problem with one line of code
  .Contact = pContact
The error is "Value of type 'Contact' cannot be converted into 'Contact'"

       
Imports Xero.Api.Core
Imports Xero.Api.Infrastructure.Interfaces
Imports Xero.Api.Example.Applications.Public
Imports Xero.Api.Infrastructure.OAuth
Imports System.Collections.Concurrent
Imports Xero.Api.Core.Model
Imports Xero.Api.Core.Model.Invoice





Public Class WebForm1

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myxeroapi As XeroCoreApi
        If IsPostBack = False Then
            'SO PAGE LOADS TWICE
            If Request.QueryString("oauth_verifier") Is Nothing Then
           
                myxeroapi = XeroAuthenticate(Me, False, "")
            Else

                myxeroapi = XeroAuthenticate(Me, True, "")
                If Not myxeroapi Is Nothing Then

                    Dim i As Integer = myxeroapi.Contacts.Find.Count 'Quck Test
                    Call oCreateInvoice(myxeroapi)


                End If
            End If
        End If
    End Sub



    Sub oCreateInvoice(ByVal myxeroapi As XeroCoreApi)

        Dim oEx As String

        Try
            Dim pContact As New Contact
            pContact.Name = "Test Company"

            'Create the list of 

Open in new window

0
Hi. I am using the following VB.net code in my ASP.net WebForms project to connect to the Xero accounting API.
It takes me to the Xero login and allows me to log in and then click the button to stay connected for 30  minutes
but then gives me the error in the attached image.  I have a web page called AccountingXero.aspx so I am not sure what I
have done wrong

Imports Xero.Api.Core
Imports Xero.Api.Infrastructure.Interfaces
Imports Xero.Api.Example.Applications.Public
Imports Xero.Api.Infrastructure.OAuth
Imports System.Collections.Concurrent

Public Class WebForm1

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myxeroapi As XeroCoreApi
        If IsPostBack = False Then
            If Request.QueryString("oauth_verifier") Is Nothing Then
                myxeroapi = XeroAuthenticate(Me, False, "")
            Else
                myxeroapi = XeroAuthenticate(Me, True, "")
                If Not myxeroapi Is Nothing Then
                    Response.Write(myxeroapi.organisation.name)
                End If
            End If
        End If
    End Sub



    Protected Function XeroAuthenticate(inpage As Page, authpagereturnedauthentication As Boolean, incode As String) As XeroCoreApi
        ' This procedure will return w working XeroCoreApi if successful and nothing otherwise
        ' Set client secrets for general use and then load any override ones from the web.config

Open in new window

0
In Visual Studio ASP.net C#  I have used the first bit of code before to send information via an API
The second bit of code is an example of how to send an invoice to the Xero accounting system.
How I merge the two to send an invoice to Xero from a C# project

public string PostEmployeeHoursEdit(List<LineEdit> DataLines, int StoreID)
{
    HttpWebResponse Resp;
    try
    {
        string url = "http://www.restaurantmagicbox.com/platform/api/";
        string API_Method = "EmployeeHours";

        string data = "";
        data = Newtonsoft.Json.JsonConvert.SerializeObject(DataLines);

        string Auth = this.txtUsername.Text + ":" + this.txtPassword.Text;
        string webAddress = url + API_Method + "/" + StoreID + "/0";
        HttpWebRequest request = HttpWebRequest.Create(webAddress);
        request.Method = WebRequestMethods.Http.Post;
        request.Headers.Add("Authorization", Auth);
        request.ContentType = "application/json";
        request.ContentLength = data.Length;

        StreamWriter writer = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
        writer.Write(data);
        writer.Close();


        Resp = request.GetResponse();
        Stream stream = request.GetResponse().GetResponseStream();
        StreamReader reader = new StreamReader(stream);
        string response = reader.ReadToEnd();

        return "OK";
    }
    catch (WebException wex)
    {
        WebResponse response = wex.Response;
        

Open in new window

0
Hi
I have the following GridView with TextBoxes. How do I remove the TextBox border in each cell or change it to white?
Thanks

        &nbsp;<asp:GridView ID="GridView1" runat="server" CssClass="Grid" OnSelectedIndexChanged="SelectedIndexChanged" HeaderStyle-CssClass="header" AllowSorting="True" AutoGenerateColumns="False" >
                    <HeaderStyle CssClass="header"  />
                 <Columns>
                      <asp:TemplateField HeaderText="Employee ID" Visible="true" ItemStyle-Wrap="true">
                           <ItemTemplate>
                                <asp:Label ID="lblEmployeeID" runat="server" Text='<%# Bind("EmployeeID")%>' Visible="true"></asp:Label>
                           </ItemTemplate>
                      </asp:TemplateField>

Open in new window

1
Hi

I have an ASP.net solution with many projects in it. I want to move one of these projects into it's own solution.
How do I do this? Is there a way to export the prfoject or should I just start a new ASP.net webforms project and import
the files?

Thanks
0
Hi. I am using the following markup for two calendars. They have to each be on their panel for my functionality to work.
They currently sit one under the other. How do I get them to sit side by side?

1
   <asp:Panel ID="PanelFromDate" runat="server" onclick="PanelFromDateClick2();">           
       <asp:Image ID="Image1" runat="server" Height="40px" ImageUrl="~/Resources/CalendarIcon.png" Width="40px" />
            <br />
            <asp:Label ID="lblFromDate" runat="server"></asp:Label>        
   </asp:Panel>

       <asp:Panel ID="PanelToDate" runat="server" onclick="PanelToDateClick2();">
            <asp:Image ID="Image2" runat="server" Height="40px" ImageUrl="~/Resources/CalendarIcon.png" Width="40px" />
                   <br />
            <asp:Label ID="lblToDate" runat="server"></asp:Label>  
            &nbsp;&nbsp;
            <asp:Label ID="lblDateError" runat="server" ForeColor="Red"></asp:Label>
        </asp:Panel>

Open in new window

0
I also want to create my own super simple membership website for my personal usage.
let us assume the db table called role has two roles, admin, user. if I want to restrict the controllers (mvc) base on the roles.
how can I do that?

[role = admin]
Controller HIAdmin
[role = user]
Controller HiUser
0
Hello Experts,
In the code below,  what happens to the value of Output parameter parm[1] and variable returnId inside and outside the USING block in C#?  Please try to help.

 { using (SqlConnection connection = SqlHelper.GetConnection())
     
               parm = new SqlParameter[2];
               parm[0] = SqlHelper.CreatePerameter("@Id", SqlDbType.VarChar, sId, ParameterDirection.Input, 50, false);
               parm[1] = SqlHelper.CreatePerameter("@Error_Msg", SqlDbType.VarChar, 0, ParameterDirection.Output, 500, false);

               returnId = SqlHelper.ExecuteNonQuery(SqlHelper.GetConnection(), CommandType.StoredProcedure, "usp_deleteRejectedItems", parm);
               strErrorMessage = parm[1].Value.ToString();
               intReturnId = returnId;
     }

    strErrorMessage = parm[1].Value.ToString();
    intReturnId = returnId;   

Open in new window


Thank you in advance for you time and help.
0
I have an input text and what I'd ;like to happen is when a a user enters a number in the input text and an input button is clicked, it  doubles the value of the text like enter 10 result is 20.
However, when a text is entered instead of a number, it would write  "Your input is wrong" in the same input text.
There are 2 inputs, one is a text and other is a button.
0
I have an asp.net website with bootstrap 4. when the window is resized or hits the medium or small breakpoint, i want to hide the side menu bar. what is the best way to achieve this?

my current layout is ,

<div class='container-fluid' > 
   <div class='sideMenu'>.........</div>
   <div class='mainContent'>......</div>
</div>

---------css--------------
.sideMenu {
      width:250px;
      border-top: 1px solid blue;
      ......
}
0
I'm trying to do this:
  • Display 2 DropDownList (one for Country, one for State)
  • When the user select a Country, it show the states or provinces for this country
  • The data where i get the country is an XML, but the choice has to be store in our MS-SQL Database using a StoreProc

I've this piece of code which affect XPath to filter the XMLDataSource for the states.  In this example i've just hardcoded "US" but i'll change that for the value taken from the Country DDL later.

protected void Country_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList list = sender as DropDownList;
        XmlDataSource wSource = (XmlDataSource)BYS.Web.UI.ControlExtensions.FindControlRecursive(this.Controls[0], "data_state");

        string wActualValue = list.SelectedValue;
        wSource.XPath = "//state[@country='US']";

    }

Open in new window


When i do this, i've this error message on the aspx web page:
(the error message is in french, i'll translate as best as i can)
The data link methods such as Eval(), XPath() and Bind() can only be used within a context of a Control linked to data
Les méthodes de liaison de données telles que Eval(), XPath() et Bind() peuvent uniquement être utilisées dans le contexte d'un contrôle lié aux données.

The XML files look like this...
Country
<?xml version="1.0" encoding="utf-8"?>
<countries>
  <country iso="CA" name="Canada" />
  <country iso="US" name="États-Unis" />
</countries>

Open in new window


State
<?xml version="1.0" encoding="utf-8"?>
<states>
  <state iso="QC" country="CA" name="Québec" />
  <state iso="ON" country="CA" name="Ontario" />
  <state iso="MO" country="US" name="Missouri" />
  <state iso="NY" country="US" name="NewYork" />
</states>

Open in new window


The ASPX file contain a FormView linked to the DS of our MS-SQL Server like this:

Open in new window

0
Hi

I am using the following code to edit two records via an API in ASP.net
I want to change it so that I can add a much larger variable number of edits
Can I use an array for instanceeg Dim DL(10000) as New LineEdit?

                        Dim DLs As New List(Of LineEdit)
                        Dim DL1 As New LineEdit
                        Dim DL2 As New LineEdit
                        DL1.LineID = 2
                        DL1.EmployeeID = 4727
                        DL1.Hours = 14
                        DL1.LogDate = "19 Apr 2019"
                        DL1.LogDate = lblLogDate.Text
                        DL1.EmplyeeWorkType = ddlWorkType.Text
                        DLs.Add(DL1)
                        DL2.LineID = 0
                        DL2.EmployeeID = 4720
                        DL2.Hours = 4
                        DL2.LogDate = "19 Apr 2019"
                        DL2.EmplyeeWorkType = "Work"
                        DLs.Add(DL2)

                        Dim result As String
                        result = PostEmployeeHoursEdit(DLs, DropDownList_Stores.Text)

Open in new window

0
Hi
In ASP.net I was told to Add this to Configuration section in web.config:
where does it actually go on that page? Is it inside   <system.web>?

    <system.web.extensions>
          <scripting> 
                  <webServices> 
                      <jsonSerialization maxJsonLength="67000000"/> 
                     </webServices>
           </scripting> 
</system.web.extensions>

Open in new window

0
Hi

In my ASP.net web app.  I am editing data via an API and sometimes
get the error I the image. My code is as follows. I have no idea what this error means

 Public Function PostEmployeeHoursEdit(DataLines As List(Of LineEdit), StoreID As Integer) As String

        Dim Resp As HttpWebResponse
        Try
            Dim url As String = "http://www.rxxdf.com/platform/api/"
            Dim API_Method As String = "EmployeeHours"

            Dim data As String = ""
            data = Newtonsoft.Json.JsonConvert.SerializeObject(DataLines)

            Dim Auth As String = Me.txtUsername.Text & ":" & Me.txtPassword.Text
            Dim webAddress As String = url & API_Method & "/" & StoreID & "/0"
            Dim request As HttpWebRequest = HttpWebRequest.Create(webAddress)
            request.Method = WebRequestMethods.Http.Post
            request.Headers.Add("Authorization", Auth)
            request.ContentType = "application/json"
            request.ContentLength = data.Length

            Dim writer As New StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII)
            writer.Write(data)
            writer.Close()


            Resp = request.GetResponse()
            Dim stream As Stream = request.GetResponse().GetResponseStream()
            Dim reader As New StreamReader(stream)
            Dim response As String = reader.ReadToEnd()

            Return "OK"

        Catch wex As WebException
            Dim response As WebResponse = 

Open in new window

0
Manual Creation of ASP.NET Code Behind Page... ?

Main Page: TCC.aspx

Code Behind Page: TCC.aspx.vb (see attached file)

Two Issues...

A. How do i Correctly Move The Code From TCC.aspx to my codebehind page... I am missing something ?
....When i move the code over and namespaces over i think i am missing a header i think or have the code wrong cause it is all red lines..
....I am using VStudio 2017 and it did not have a checkbox choice to create code behind page ?

and...

B. Can I change this to C# later (when i have it correct)  by just changing the Page Language to C# and rewriting the code behind modules in C# ??

TCC.aspx
<%@ Page Language="VB" AutoEventWireup="false" Codefile="TCC.aspx.vb" Inherits="TCC" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.UI.Page" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.data.OleDb" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Register Assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="System.Web.UI.WebControls" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Page.EnableViewState = False
        DateToday.Text = 

Open in new window

0
Hi

I have a GridView which has 30 template textbox columns, 4 of which are shown below.
They go from D1 through to  D30
I want detect all cells or text boxes where the value has changes when I click a button
How do I monitor and maintain a record of all cells that are changed?

   <asp:TemplateField HeaderText="D1" Visible="false" ItemStyle-Wrap="true" >
                           <ItemTemplate>
                                <asp:Textbox ID="D1" runat="server"  Visible="true" Width="20"></asp:Textbox>
                           </ItemTemplate>
                      </asp:TemplateField>
                      <asp:TemplateField HeaderText="D2" Visible="false" ItemStyle-Wrap="true" >
                           <ItemTemplate>
                                <asp:Textbox ID="D2" runat="server"  Visible="true" Width="20" ></asp:Textbox>
                           </ItemTemplate>
                      </asp:TemplateField>
                     <asp:TemplateField HeaderText="D3" Visible="false" ItemStyle-Wrap="true">
                           <ItemTemplate>
                                <asp:Textbox ID="D3" runat="server"  Visible="true" Width="20" ></asp:Textbox>
                           </ItemTemplate>
                      </asp:TemplateField>
                      <asp:TemplateField HeaderText="D4" Visible="false" ItemStyle-Wrap="true" >
                           <ItemTemplate>
                                <asp:Textbox ID="D4" runat="server"  

Open in new window

0
Hi

I have an ASP.net button that runs code that checks the cell backcolors.
The problem is that none of the cell colors are detected as blue because they were cleared on a postback before
the code runs. How do I run the VB.net code before the colors are cleared?
    Protected Sub btnSaveChanges_Click(sender As Object, e As EventArgs) Handles btnSaveChanges.Click

        Try

            Me.lblSaveChangesError.Text = ""
            Dim oDateList As String = TryCast(Session("oDateList"), String)
            Dim arrDates As Object = Split(oDateList, ",")
            Dim oNumberDays As Integer = UBound(arrDates) + 1
            Dim oTextColumnName As String
            Dim oColumnIndex As Integer
            Dim oCellValue As String
            Dim oToolTip As String
            Dim T As TextBox
            Dim oBackColor As System.Drawing.Color

            For r As Integer = 0 To Me.GridView1.Rows.Count - 1
                For d As Integer = 1 To oNumberDays
                    oColumnIndex = d + 1 'First column index is 2
                    oBackColor = Me.GridView1.Rows(r).Cells(oColumnIndex).BackColor
                    If oBackColor = System.Drawing.Color.Blue Then
                        'so if cell ccolor is blue....
                        oTextColumnName = "D" & CStr(d)
                        T = Me.GridView1.Rows(r).FindControl(oTextColumnName)
                        oCellValue = T.Text
                        oToolTip = T.ToolTip

                   

Open in new window

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