This is a small tutorial on getting/reading submitted data from ASP.NET pages.

In PHP, you write a form, put in your inputs (i.e. test_name), then some buttons. Usually you would catch this by doing a:

echo $_POST['test_name'];

In ASP.NET C# you get your post variables by using Request.Form:

Request.Form["test_name"]

To send the data, with your submit button, simply have the METHOD=”?action=update” or if you’re using an ASP Button control, the PostBackURL should be “?action=update”

Now you need to catch the post back, and do something with the information you’ve sent to the server.

To see what button has been clicked, use QueryString:

                Request.QueryString["action"];

Put all this together:

                string action = Request.QueryString["action"];
                if (action == "update")
                {
                    name = Request.Form["test_name"];
                }

Easy! :)

Tags: , , , ,

· · · ◊ ◊ ◊ · · ·

When you’re working with Visual Studio, you will always run into odd problems – this is one of them.

When working with Javascript, C# and VS you sometimes want to debug the Javascript directly in the IDE… but you get the silly:

the breakpoint will not currently be hit no symbols have been loaded

the breakpoint will not currently be hit no symbols have been loaded

One way around this (an easy, but dirty way) is to open up Internet Explorer, and go to tools (if you’re using Internet Explorer 8 and above you may need to press the ALT button to show the file menu) then click the ‘Advanced’ tab, and check ‘Display a notification about every script error’.

Then, when you get an error… it will pop up and ask whether you’d like to debug it. Follow the prompts and debug it in a new instance of Visual Studio. You will be able to see the breakpoint, and you’ll be able to use the built-in debugging features, like step in.

 

Tags: , , ,

· · · ◊ ◊ ◊ · · ·

At work the other day, we had an issue regarding reporting services. We have two servers, one is the test and one is the live server.

The requirement was:

  1. When debugging the web application, point to the test Reporthost
  2. When running in ‘Release’, point to the live Reporthost

We figured that we could use web.config transformations – that is, two different web.config files for the two solution configurations: Web.Config, Web.Debug.Config, and Web.Release.config.

Unfortunately, we found that this wouldn’t work after a lot of research and trial and error – it only works when the project is published (deployed).

Refusing to be beaten by Visual Studio, we decided to use the Build Event feature, and for whatever solution configuration the project was currently set to, we would search the specified files and replace the text (i.e. From TestReporthost to LiveReporthost). We shortly realized that we would need a third party tool to help with this, and that was the FART tool (http://fart-it.sourceforge.net/).

The prebuild event:

if $(ConfigurationName) == Debug (
$(SolutionDir)debug.bat
) ELSE (
$(SolutionDir)release.bat
)

The bat file(s):

X:\App\fart.exe -i <pathtofile> <find> <replace>
EXIT 0

Everything worked beautifully, and the requirements were met.

Tags: , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

One of the hurdles of using a C library in C++ in the shift in the Object Orientated paradigm. Knee-jerk reaction is to write a wrapper to make it more OO friendly.

This comes in handy if you’re going to implement conversion between data structures.

However, recently participating in a game jam I found it easier to simply call the C functions right off the bat. If you name your functions correctly, you can save time while writing clear, conceive code. As much as your university professor is screaming.

So should I write a wrapper for these C functions?

  • Yes – if your code is well named. play_sdl_chunk_with_vector(*MIX_CHUNK,vector3df &) style function names.
  • No – if your code looks like dog food. pscml(*MIX_CHUNK,irr::core::vector3df) is not a good name. Wrap that shit

Tags:

· · · ◊ ◊ ◊ · · ·

When you’re working with ASP.NET (C#) and the ReportViewer control, you will probably want to export that report as CSV or Excel (programmatically).

Here’s a snippet of what I’ve used. Simply call the method and voila, you’ll be asked to download the file.

Export(ReportViewer1, “CSV”);
Export(ReportViewer1, “XLS”);

      public bool Export(ReportViewer viewer, string exportType)
        {
            Warning[] warnings = null;
            string[] streamIds = null;
            string mimeType = string.Empty;
            string encoding = string.Empty;
            string extension = string.Empty;
            string deviceInfo = string.Empty;
            string filetype = string.Empty;
            string reportsTitle = GetReportTitle(viewer); // just gets the Report title... make your own method

            //ReportViewer needs a specific type (not always the same as the extension)
            if (exportType == "XLS")
            {
                filetype = "Excel";
            }
            else
            {
                filetype = exportType;
            }

            byte[] bytes = viewer.ServerReport.Render(filetype, null, // deviceinfo not needed for csv
                out mimeType, out encoding, out extension, out streamIds, out warnings);

            System.Web.HttpContext.Current.Response.Buffer = true;
            System.Web.HttpContext.Current.Response.Clear();

            System.Web.HttpContext.Current.Response.ContentType = mimeType;
            System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + reportsTitle + "." + exportType);

            System.Web.HttpContext.Current.Response.BinaryWrite(bytes);

            System.Web.HttpContext.Current.Response.Flush();
            System.Web.HttpContext.Current.Response.End();

            return true;
        }

It would be incredibly easy to turn this into a class, that can do a whole bunch of different formats. It’s very easy to turn this code into exporting a PDF document — but it’s a wee bit different.

To select which format I wanted a report to be exported as, I used the following:

Markup:

                        <asp:DropDownList id="DropDownListExport" runat="server" >
                             <asp:ListItem Value="XLS">Excel</asp:ListItem>
                             <asp:ListItem Value="CSV">CSV</asp:ListItem>
                        </asp:DropDownList>
                        <asp:Button id="Button1"  Text="Export" OnClick="Export_Click" runat="server"/>

Code-behind:

        public void Export_Click(object sender, EventArgs e)
        {
            string type = DropDownListExport.SelectedItem.Value;

            Export(type, ReportViewer1);
        }

If you’d like any help regarding this, leave a comment.

Tags: , , , , , , , ,

· · · ◊ ◊ ◊ · · ·