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

How can share/re-use the Site.Master with all my applications on my workstation (IISExpress) as well as on my Test and Production servers?

I create an application with the a blank page and published it to the my test server.

How I get my other applications to use the site master of this new application as their site master. Do I create a virtual directory in each application that contains this new application?

What is the best approach?

Thanks
0
Hi

In my ASP.net web app I bind a datatable to a GridView. The number of columns in the datatable differs each time so I can't manually create
template textbox columns. Is it possible to dynamically create textbox columns for every second column.?

Thanks
0
Hi. I use the following code to in my ASP.net web app to allow the user to click a GridView cell that then loads the information
pertaining to that cell to other controls to allow editing. I would like to also make the editing possible in the gridview cell by turning
it into a text box. How would I do that? I cannot use Template columns and AutoGenerateColumns is true

   Private Sub GridView1_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowCreated

        Dim dtNew As DataTable = TryCast(Session("dtNew"), DataTable)
        If e.Row.RowType = DataControlRowType.DataRow Then
            'Following link shows how cells are made clickable
            '//https://stackoverflow.com/questions/31202877/get-clicked-cell-index-in-gridview-not-datagridview-asp-net
            For i As Integer = 0 To e.Row.Cells.Count - 1
                Dim cell As TableCell = e.Row.Cells(i)
                cell.Attributes("onmouseover") = "this.style.cursor='pointer';this.style.textDecoration='underline';"
                cell.Attributes("onmouseout") = "this.style.textDecoration='none';"
                cell.ToolTip = "You can click this cell"
                cell.Attributes("onclick") = String.Format("document.getElementById('{0}').value = {1}; {2}", SelectedGridCellIndex.ClientID, i, Page.ClientScript.GetPostBackClientHyperlink(CType(sender, GridView), String.Format("Select${0}", e.Row.RowIndex)))
            Next
        End If


    End Sub

    Protected

Open in new window

0
Hi. I am fairly new to JavaScript. How do I step through JavaScript and put line breaks in.
My code resides in an ASP.net VB.net web app

<script type="text/javascript">
        //variable that will store the id of the last clicked row
        var previousRow;
        
        function ChangeRowColor(row)
        {
            //If last clicked row and the current clicked row are same
            if (previousRow == row)
                return;//do nothing
            //If there is row clicked earlier
            else if (previousRow != null)
                //change the color of the previous row back to white
                document.getElementById(previousRow).style.backgroundColor = "#ffffff";
            
            //change the color of the current row to light yellow
 
            document.getElementById(row).style.backgroundColor = "#ffffda";            
            //assign the current row id to the previous row id 
            //for next row to be clicked
            previousRow = row;
        }
     </script>

Open in new window

0
I have a jquery function that fills a dropdownlist, then selects a value from the list.  The function to fill the list works and the value that it attempts to put in there is one in the list.
problem is it does not select.  but if I put a alert() after the drop down fill and then after I click the alert box the value is selected.  Its like the list is not there, but the alert allow it to fill then the select happens

		function SetScreen(AccountKey,ValueToSelect)
		{
                    fillDropdown(AccountKey);
		 // id i put an alert('wait'); it selects and works   ****************
                   $("#Search").val(ValueToSelect);	  
		  
		)
// this works fine
		function fillDropdown(Account) {
			$.ajax({
				type: "POST",
				url: "getValues.ashx?prefix=" + Account,
				contentType: "application/json; charset=utf-8",
				dataType: "json",
				success: function (data) {
					var ddlCustomers = $("#Search");
					ddlCustomers.empty().append('<option selected="selected" value="0">Please select</option>');
					$.each(data, function () {
						ddlCustomers.append($("<option></option>").val(this['Value']).html(this['Text']));
					});
				}
			});
		}

Open in new window

0
Hi

In ASP.net I have a GridView control that I used to load data from multiple data sources.
When the user selects something in the GridView I want to get the selected row index as well as the column index.
How do I do this in a raw GridView that has no template columns?
0
Hi

In an ASP.net GridView if the property AutoGenerateEditButton is set to true and I click on the Edit button I get the error
The GridView 'GridView1' fired event RowEditing which wasn't handled.

What code do I need to add in to allow editing?
0
I have a web app that is multi tenant

There is a select (dropdown) in the layout.cshtml
This contains a list of locations

When you select a different location, it reloads the page and populates data relevant to that location by appending a parameter
i.e.
?siteId=4

Open in new window


This is all working fine
There are many different pages in the navigation (Li's in  layout.cshtml)

The issue is, the siteId is forgotten when i visit a new page, and just loads the default site (first one in list)
I was thinking of storing this siteId in session and referring to this,
I'm wondering if there is another solution?
0
Hi

In my ASP.net web app a user selects a from and to date and a datatable loads into a GridView with a column
for each date. I want a user to be able to select one of the items or "cells" in the gridview and change the number in it.
Ordinarily I use template columns to do this because I know exactly which columns will load but in this
case any number of date columns can load.

1
0
I have a layout.cshtml which all pages use

I have a HTML SELECT on this layout
When someone changes the drop down, it fires this code

   $('#sitesDdlLayout').on('change', function () {

                        var selectedSiteId = $("#sitesDdlLayout option:selected").val();

                         $.ajax({
                            type: "POST",
                             url: "@Url.Action("RedirectToSiteById", "Home")",
                            data: "{'SiteId':'" + selectedSiteId + "'}",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (response) {

                                window.location.href = response.Url;

                            }
                         });
                });

Open in new window


Then it fires this
   [HttpPost]
        public ActionResult RedirectToSiteById(string SiteId)
        {
            var redirectUrl = new UrlHelper(Request.RequestContext).Action("Index", "Home", new { SiteId = SiteId });
            return Json(new { Url = redirectUrl });
        }

Open in new window


This works fine, apart from always redirecting to the INDEX page

What I want to do is to reload the current page, and pass in query string of SITEID into the URL which will then pull in the correct content based on the site

i,e, something like this
 
       $('#sitesDdlLayout').on('change', function () {

                        var selectedSiteId = $("#sitesDdlLayout option:selected").val();
                      ....
                        url: "@Url.Action("CURRENTPAGE", "Home", URLPARAMETERHERE)",
                      ....

Open in new window


the idea is the user stays on same page,  but its reloaded with the correct SiteId appended to the URL
Any ideas the best way to do this inside the layout.cshtml file?
0
I haven't worked with cloud so i don't know how and if this would work...

I'm looking for a HIPAA compliant cloud storage. I want to have folders there. User can upload their documents there (with C# code,if possible) and I want to read them from my C# code (download them).

Is that doable?
0
ASP.NET + JavaScript + Client Side CustomValidators - I Have Question  

I have a ASP.Net standard Web Form working on validation - www.enflow.com/CC/P1/EE.aspx

Click The Other Button and a text box will appear... do not put any text into that textbox

Now Click Submit Button and you will CORRECTLY get a Validation Summary Msg saying missing text for the Describe Other textbox

But if you put text into that textbox and click submit button again then you will keep getting the same validation error...

I think i am missing something simple in JScript ClientSide Validation Call or ??


Here is JScript for Client JS Call...
      function valOther(sender, args) {
          if (document.getElementById("<%=Other.ClientID %>").checked == true) {
              if (document.getElementById("<%=MoreOther.ClientID %>").value === null) {
                  args.IsValid = true;
              } else {
                  args.IsValid = false;
              }
          }
      }

Open in new window

Here is All the Code In this Webform
<%@ 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, 

Open in new window

0
I have a layout.cshtml page

I'm trying to get a simple alert('hi'); to fire, but none of the alerts below are firing

 @section scripts{
        <script type="text/javascript">
               alert('hi');
            $(document).ready(function () {

                alert('layout');
               
            });

        </script>
    }

  @RenderBody()


    <!-- PAGE FOOTER -->
    <div class="page-footer">
        <div class="row">
            <div class="col-xs-12 col-sm-6">
                <span class="txt-color-white">@ViewBag.Footer</span>
            </div>

        </div>
    </div>


  @RenderSection("scripts", required: false)

Open in new window



Is there some special order i have to follow to get this working?
0
Hello Experts,
I have an exiting program in C# which call an API.  The API returns more than 100 rows.  The C# program looks as below.

var memberFound = MemberSearch(Date);
if (memberFound != null)
	foreach (var member in memberFound)
	{
	    var list = new List<string>();
	    list.Add(member.memberNumber);
	}

Environment.Exit(0);

Open in new window


I am trying to parse the data in stored temporary in the member variable (or memberFound) which contains the following information.  The data stored looks like an Array, but not works like that.  I am trying to pass (member or memberFound) data to another method where I can parse the data and Insert to a table.

Here I have hard time understand var data type.  Please try to help.

memberCode = 1001                        
age = 32
name = Mark John
memberType = "xxx"
balanceAmount = 2450.00
.
.
.

Open in new window


Thank you very much in advance.
0
I have a webform that has dropdowns and textboxes. I created a stored procedure and code behind to insert the data, now i'm trying to consolidate an update were the user would only need to use one button. Once the button is inserted or saved the button is clicked it would only show update. It would only show update or do an update if the Primary Key is created so there would have to be a select statement as well. I could even accept a way where there are two buttons. After empty webform is loaded the insert button is enabled but update disabled and once insert button is clicked it is disabled indefinitely and update is enabled indefinitely since there is already a newly created primary key.  

here are the insert and updates in the code behind:

Insert code:
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim strConnString As String = ConfigurationManager.ConnectionStrings("MerchData").ConnectionString
        Dim con As New SqlConnection(strConnString)
        Dim cmd As New SqlCommand()

        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "[dbo].[InsertPurchaseOrder]"
        cmd.Parameters.Add("@Suppint", SqlDbType.VarChar).Value = ddlSupplier.Text.Trim()
        cmd.Parameters.Add("@VendorCode", SqlDbType.VarChar).Value = tbsuppliercode.Text.Trim()
        cmd.Parameters.Add("@classgroupAllocID", SqlDbType.VarChar).Value = If(ddlclass.Text = String.Empty, DBNull.Value, CType(ddlclass.Text, String))

Open in new window

0
Hello,
Is there a difference between  a C# ASP.NET SQL insert query and a C# Windows Forms  insert query.  Below is my ASP.NET SQL Insert Query:
 
                                    mCommand.Parameters.AddWithValue("@CallDate", ReportData.CallDate);
                                    mCommand.Parameters.AddWithValue("@CallTime", ReportData.CallTime);
                                    mCommand.Parameters.AddWithValue("@CallNumber", ReportData.CallNumber);
                                    mCommand.Parameters.AddWithValue("@Narrative", ReportData.Narrative);
                                    mCommand.CommandText =
                                        "Insert INTO DataPreHospital (StudentID, CallDate, CallTime, ResponseType, CallNumber, CallType," +
                                        " CallDisposition, Age, Sex, Race, Weight, Phase, Status, " +
                                        " PrehospitalAgencyID, PrehospitalUnit, Narrative) Values (" +
                                        ReportData.StudentID + ",  @CallDate, @CallTime," +
                                        ReportData.ResponseType + ", @CallNumber, " +
                                        ReportData.PatientType + ", " +
                                        ReportData.CallDispositionID + ", " +
                                        ReportData.Age + ", " +
                                        ReportData.Sex + ", " +
                                        …
0
Visual Studio 2017 ASP.net C#   -    

I have numerous checkboxes that are filled from a database.  When default page loads (and is not a postback) the lists are read from the database and placed into Caches.  

 Cache ACachce =  new Cache();
  ACachce.Insert(cacheName, ds, null, DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration,  CacheItemPriority.High, null);
  con.Dispose();
  return ds;    // a dataset


When I redirect to another page (not postback) the Caches are used to fill the checkboxes.   For example:  
if (chkChiefComplaint.DataSource == null)
       {
               chkChiefComplaint.DataSource = Cache["ChiefComplaint"];
               chkChiefComplaint.DataBind();
       }

Three other forms used the same checklists and read the Caches.  

My problem is that often (but not always) when redirecting to another page, the checkboxes are not filled.  If I return to the Default and then redirect back, the boxes are eventually filled, but it may take 2 to 3 rotations.    Once the boxes fill upon a page load they always filll  for any of the pages.  Sometimes the boxes fill correctly the first time a redirect is made.   The problem occurs in Chrome, IE, and Edge.   I have used try/catches to check for any errors.  

I do not know if it makes a difference, but these are Devexpress controls that are part of a Devexpress ASPX.FormLayout control.

I realize that this is a rather ambiguous problem, but any ideas or suggestions are greatly …
0
I have some domain names (my manager came up with them). How can I tell if they've already been registered/taken by others? do I need to check with GoDaddy?
0
User has filled out the form and is navigating away without saving. I want a custom alert to display, warning them and asking if they wish to proceed or save.

I searched on here, but the result was from 2007. Gotta be something more modern out there. I've seen them.

I was told that this can only be done using the browser's built in alerts, but I'm sure I've seen custom, nice looking alerts.

Any suggestions where I can find something?

thanks!
0
Hi

In my ASP.net web app I pull data through to a GridView. One of the columns is  Date column.I have now been asked
to show the data with the dates along the top horizontally as opposed to vertically in a column. How would I go about this?
The image shows the dates at the top.

1Image1.png
0
Hi

In my ASP.net VB.net web app I am trying to view an image in one of my folders using the following two lines but the image is not appearing

     Dim FilePath As String = Server.MapPath("~/Uploads/" & oSelectedFile)
     Image1.ImageUrl = FilePath

Open in new window

0
I have a label in a repeater. The label has an onclick event, which requires it use an apostrophe rather than a double quote. But I also use a datacolumn in the onclick event as a parameter and it requires a single quote.

I've tried escaping the single quote inside the onclick event. No.
I've tried leaving out the quote when I pass the parameter. No.

Here is what I have:

<asp:Label ID="btnViewMore"
Text='<%# Eval("dcViewMore").ToString()%>' CssClass="stylViewMoreBtn"
OnClick='loadOverview("<%# Eval("dcEmployeeId").ToString()%>;return false;")' runat="server"></asp:Label>

Open in new window


How do folks use a datacolumn in an onclick event where a single quote is required? thanks!
0
Hi

In ASP.net what code would I use to check if a certain file is a pdf. I want to add this check to the following code

    Protected Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
        Try
            Dim oSelectedFile As String
            If Me.ListBox1.SelectedItem.Text <> "" Then
                oSelectedFile = Me.ListBox1.SelectedItem.Text
            Else
                Exit Sub
            End If
            'Response.Clear()
            'Dim filePath As String = "~/Uploads/" & oSelectedFile
            'Response.ContentType = "application/pdf"
            'Response.WriteFile(filePath)
            'Response.TransmitFile(filePath)

            'Dim FilePath As String = Server.MapPath("piyushsir.pdf")
            Dim FilePath As String = Server.MapPath("~/Uploads/" & oSelectedFile)
            Dim User As New System.Net.WebClient()
            Dim FileBuffer As [Byte]() = User.DownloadData(FilePath)
            If FileBuffer IsNot Nothing Then
                Response.ContentType = "application/pdf"
                Response.AddHeader("content-length", FileBuffer.Length.ToString())
                Response.BinaryWrite(FileBuffer)
            End If

        Catch ex As Exception
            'Response.Write(ex.Message)
            Me.lblErrorDeleting.Text = ex.Message & " hr556"
        End Try
    End Sub

Open in new window

0
Hi. In my ASP.net web app I am using the following code to view a pdf file. If I want to view an image file such as a jpg or png
file what code would I use? Thanks
    Protected Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
        Try
            Dim oSelectedFile As String
            If Me.ListBox1.SelectedItem.Text <> "" Then
                oSelectedFile = Me.ListBox1.SelectedItem.Text
            Else
                Exit Sub
            End If
            'Response.Clear()
            'Dim filePath As String = "~/Uploads/" & oSelectedFile
            'Response.ContentType = "application/pdf"
            'Response.WriteFile(filePath)
            'Response.TransmitFile(filePath)

            'Dim FilePath As String = Server.MapPath("piyushsir.pdf")
            Dim FilePath As String = Server.MapPath("~/Uploads/" & oSelectedFile)
            Dim User As New System.Net.WebClient()
            Dim FileBuffer As [Byte]() = User.DownloadData(FilePath)
            If FileBuffer IsNot Nothing Then
                Response.ContentType = "application/pdf"
                Response.AddHeader("content-length", FileBuffer.Length.ToString())
                Response.BinaryWrite(FileBuffer)
            End If

        Catch ex As Exception
            'Response.Write(ex.Message)
            Me.lblErrorDeleting.Text = ex.Message & " hr556"
        End Try
    End Sub

Open in new window

0
ASP.NET webforms has the below events
•      PreInit (IsPostBack and Session available)
•      Init
•      InitComplete
•      PreLoad (ViewState for all controls)
•      Load (Values of controls loaded)
•      LoadComplete (All event handlers raised)
•      PreRender (Last chance to do anything before appearance of form).
•      PreRenderComplete
•      SaveStateComplete (ViewState saved for the page and all controls)
•      Render
•      Unload

What does ASP.NET MVC do?
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