I have a local version and version that is hosted by IIS onto a server.
When i click the link to load up my page all the styling is fine and it suppost to be where it is:
I choose all my data and submit my page which runs this C# code.
newRecord.NumberofItems = Convert.ToInt32(totalitems);
cPostFunctions test = new cPostFunctions();
test.InsertNewRecord(newRecord);
//Add Message
Response.Write("<script langauge=\"javascript\">alert(\"Entry Submitted\");</script>");
Page_EntrySubmitted(null, EventArgs.Empty);
In the Page_EntrySubmitted method all it does is set the Textboxes, Dropdowns and labels to NULL.
When the page refreshes after the alert this happens:
All my styles are getting pulled through but it seems as it is stretching everything.
THIS ONLY HAPPENS ON THE SERVER NOT MY LOCAL VERSION
Related
I'm trying to bind/fill a GridView. The GridView is the only thing on that page. No editing or anything, just a list of data. The event that triggers the GridView fill method is on a different page. The call to the method seems to work but when it gets to the GridView it complains that I need to reference an instance of the object.
I've tried at least a dozen approaches. This should be simple. I'm currently doing different variations on FindControl.
Here is the C# code that is failing:
Default.aspx.cs
public class ImportCSV : System.Web.UI.Page
{
public ImportCSV()
{
// A bunch of code that is working.
GridView LoadedDrivers = (GridView)Page.FindControl("LoadedDrivers");
LoadedDrivers.DataSource = csvDataTable; //This is where it errors
LoadedDrivers.DataBind();
)
Here is the code that triggers it:
Control.aspx.cs
namespace ControlPanelLab
{
public partial class Control : System.Web.UI.Page
{
//Working code
public void LoadDriversDriversButton_Click(object sender, EventArgs e)
{
//_Default.ImportCSV();
_Default.ImportCSV importCSV = new _Default.ImportCSV();
}
And the GridView that needs to be filled:
Default.aspx
<%# Page Title="Driver Table" Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="Default.aspx.cs" Inherits="ControlPanelLab._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView ID="LoadedDrivers" runat="server" AutoGenerateColumns="true"></asp:GridView>
</asp:Content>
I've tried every combination I can think of and this at least compiles without an error. It just blows up when I run it complaining about referencing an instance of the LoadedDrivers GridView. I tried to put all the logic in a separate class file but I couldn't get that to work. The ImportCSV method was originally in a button handler that worked but I had to relocate the button that triggers the event to a different page. I tried to trigger that button with a button event sent by the new control page.
What am I missing? Thank you for any help.
Update -
I should point out that the only thing happening on the Control page is the button that triggers the method which loads, parses and ultimately needs to repopulate the GridView.
The button event on the Control page does in fact start the process just fine. All of the other activity is occurring on the Default page. And the only thing that is not working is the GridView which exists on the Default page is not binding.
I do understand that I do not understand inheritance all that well. That is why I am looking for guidance.
I have read many posts about triggering button clicks with JS as well as many posts about referencing precompiled classes.
The reference that I show in my code does not work, I get that. That's why I'm asking. Logically, there needs to be a way to trigger an event from a location that is not explicitly on the same page as the element being triggered. It's all under the same site, indeed, shares a namespace.
How do I properly address it?
Edit to include full ImportCSV method:
public ImportCSV()
{
//Static path to csv file
string csvPath = ("C:/Data/drivers.csv");
//Create a DataTable.
DataTable csvDataTable = new DataTable();
csvDataTable.Columns.AddRange(new DataColumn[4] { new DataColumn("id", typeof(int)),
new DataColumn("fName", typeof(string)),
new DataColumn("lName", typeof(string)),
new DataColumn("Country",typeof(string)) });
//Read the contents of CSV file.
string csvData = File.ReadAllText(csvPath);
//Execute a loop over the rows.
foreach (string row in csvData.Split('\n'))
{
if (!string.IsNullOrEmpty(row))
{
csvDataTable.Rows.Add();
int i = 0;
//Execute a loop over the columns.
foreach (string cell in row.Split(','))
{
csvDataTable.Rows[csvDataTable.Rows.Count - 1][i] = cell;
i++;
}
}
};
GridView LoadedDrivers = (GridView)FindControl("LoadedDrivers");
LoadedDrivers.DataSource = csvDataTable;
LoadedDrivers.DataBind();
When I debug the code, it runs right up to the GridView statement where it throws the exception. All of the variables populate in the locals pane. I can see the data in csvDataTable.
There is a Site.Master page which very well could be an elephant.
The other elephant might be that I was instantiating the ImportCSV from the Controls page button handler. I have changed that so the only thing being done on Controls is to click a button handler on Default and let it all exist in that space. I'm still missing something. The ImportCSV method works fine in several other elements of the project. I haven't needed to use FindControl in other places.
Unfortantly, you VERY much miss understand how a web server works.
Unlike desktop software?
The web system is called state-less. That means a copy of the web page ONLY exists client side. the web server does not keep in memory a copy of each users web page. In fact it does not even KEEP ONE copy in memory!!!
If 5 users all have the same web page open? There are NOT 5 instances of the web page class server side. In fact the .net class that represents the web page is NOT even existing, nor in memory.
If one user clicks a button on their web page? the ONE web server is just sitting there. If a post back occurs? Then the web server springs into action, load the page class, creates a NEW instance (and thus all variables in that page start from SCRATCH EACH TIME a post is made. The class instance is created, it now runs based on that page posted by the user. Rendering is done, and then the page is sent back to the client side and the CLASS COPY IN MEMEORY IS DISPOSED AND TOSSED OUT!!!
It does NOT exist anymore. So, if you try to reference a instance of that page class in another web browser from code behind, you find that the page class is NOT even memory, and all of its values (code variables) don't even exist!!!
So, the web server does not manage a page in memory for EACH user! The web server is just sitting there, waiting for ANY user to post back a page for processing. It is ONLY during that VERY short time when code behind runs does the instance of that class exists. Once the server has send the page back to the user, that class instance is tossed out and is gone!!!
So, you in fact have this setup:
Note how the page is sitting CLIENT side. On the server, THERE IS NOT a instance of that page class.
NOTE VERY careful here - the web page is ON CLIENT computer - it is NOT existing at all on the web server side.
You do not have this:
And you DO NOT HAVE this either:
Ok, You click the button. Now the so called round trip starts.
our web page is sent up to the server. You now have this:
So NOW your page is sitting on the server.
NOW a instance of the page class is created, and your code behind starts running.
Your code behind can modify controls (even visible), but the page is NOT interacting with the user - ONLY code can MODIFY the web page.
It is THEN sent back to the client side, and the server side class instance and code is TOSSED OUT - DOES NOT exist!!!
You now have this:
So, you can't do as you ask!! The server side instance of that other page is GONE!!!
And you would never know what user in question that class instance of that page belonged to if you could do this.
The web server is NOT like desktop software. The web server serves pages out to EVERYONE - the class instances of those pages don't exist until a post back occurs.
What you could do is have a timer on the first page. It could fire say every second, check some session value, and if your other page sets that session value, then the first page could load the grid. But you can't as a normal rule "garb" and paly with a instance of another page, since that instance DOES NOT exist!!!
(the page is sitting client side - NOT server side.
I have an ASP page with a table containing always different rows, dynamically loaded from a MSSQL DB. In each row of the table I have created a Button, called Details, that is dynamically created during the writing of the table. This Details button is added with the following code:
Button detailsButton = new Button();
detailsButton.Height = new Unit("18px");
detailsButton.Width = new Unit("65px");
detailsButton.Text = "Details";
detailsButton.ID = row.ItemArray[0].ToString();
detailsButton.PostBackUrl = "~\\DetailsPage.aspx?selectedSignalling=" + detailsButton.ID;
//detailsButton.Click += detailsAgencyButton_Click;
//detailsButton.OnClientClick = "return true;";
table1cell4.Controls.Add(detailsButton);
table1row.Cells.Add(table1cell4);
The intention is to redirect the client towards the Postback URL when one button is pressed on a row. The Postback URL is dynamically created for each button, associating to each of them the ID of the item that the user would choose to display the details.
While this works fine on the my development environment, that is running IIS 7.5, this is not always working on the production environment, that runs IIS 6.0 and that cannot be updated. On IIS 6.0, some clients does not notice any problem, while others are not able to display the details page, but, when clicking on the Details button, the postback URL is not loaded and instead there is only the reload of the current page.
I have tried to change many settings (set the detailsButton.Click, set the OnClientClick to "return true;"), but without luck. I have only noticed that adding the:
detailsButton.OnClientClick = "return true;";
instruction, the redirect does not work in IIS 7.5 too. So it seems to me that when OnClientClick returns something (true/false), the PostBack is not activated, while some of the clients probably does not return any OnClientClick and the PostBack is activated.
I solved my problem using javascript redirect associated to onClientClick event and returning false on the same event. This prevents the server to be invoked and the client redirects towards the new page without refreshing the old page.
detailsButton.OnClientClick = "windows.open(' new_page.aspx ', '_self'); return false;";
Got a strange one, here.
I'm working on a basic ASP.NET/C# code-behind app where summary data is listed in a grid, and each record has an accompanying "update" button. Clicking the button triggers a window.open() where the ID for each row of the grid is passed into a query string to retrieve the related record for edit in the new window.
Example from the rendered "grid" page:
window.open('EditTool.aspx?ID=' + ID, 'new_window', width=550, height=300');
When the page opens from the button, it can take upwards of 10 seconds to render. When I open a new tab and just paste the URL and query string content into the address bar, the page renders almost immediately.
I've peppered the content of the page with log4net statements, and it looks like all of the controls and code-behind C# executes in a few milliseconds.
For investigation's sake, I've got popup blockers deactivated, and I've tried this on IE7 (workplace standard, ugh), FF, and Chrome.
Any ideas as to how to make the rendering faster, or where else I can look to see what's slowing it down?
Update:
I've created a new shell webapp that has a button opening an empty (just the stuff that gets added when you "Add New Item") ASPX as a popup. The popup renders immediately. I've also modified my existing app to open an empty popup, and I get the same delay. It's looking like the app server is waiting to process something before it starts processing the page, rather than rendering the page, slowly.
Does ASP.NET have a setting where you can tell it not to recompile a page on each render?
I'm working on an application that connects to a serial port. I have experience in C#, but not so much in asp.net.
I have a Label on an aspx page which displays the status of the connection. When I click a button, a new page opens which let's you select the serial port you want to use. When you press the OK button on that page, it will send you back to the original page with the label.
Initially, the label says: "Status: Not connected". I'm saving this string in a globaldata class so I can access the string. I want that when you click the OK button on the new page, it will change the label to "Status: Connected", so when the original page loads the label will be changed.
So in the OK button I added onclick="butOK_Click" and then in the event I change the string in the globaldata class. However, I don't know how to get back to the page. Adding a PostBackUrl="Home/Index" (where Home/Index is the begin page with the label) does return to the begin page, but doesn't execute the code that changes the string.
How can I achieve what I want?
EDIT: now that I think about it, I only want to change the label after executing a function that actually connects to the serial port. I already have this function, it just needs to let the page know that it is connected.
Response.Redirect("~/Home/Index.aspx");
Something very odd is happening here.
I have a custom WebPart within Sharepoint which sends forms to Excel and by E-Mail. I'm using Asp.NET 3.5, Ajax, jQuery.
Inside OnInit() I'm connecting to TeamFoundation Server, opening an excel template, initializing jQuery, and loading up the css.
CreateChildControls() adds the controls to panels and such, and creates an empty literal i'm calling "litScript".
Inside PreRender(), I'm updating values based on partial (or not) postbacks and such. I also assign a value to litScript, which composes some layout rounding effect, a jQuery-based tab effect, and mouse-following progress icon.
I have many tabs with buttons which, upon clicked, process some stuff.
Upon assigning a random text "I'm here!" to a label inside some button click event, it reloads perfectly.
cc.GetTextControl("lblTeste").Text = myForm.PostbackMessage;
(cc.GetTextControl just returns my control).
However, by using my literal and writing
cc.GetTextControl("litScript").Text = "<somejavascript>"+myForm.PostbackMessage+"</somejavascript>";
I don't get anything.
When I do a full postback, everything loads correctly though.
What is happening?
Had something to do with javascripts not changing. I just added a RegisterClientScriptBlock and everything went fine.