Archive for October, 2012

Removing a .NET Session variable with JavaScript

Want to clear an ASP.NET session variable from JavaScript? Of course you do – all the cool developers are doing it. First, create a JavaScript function that uses an XMLHttpRequest class to make a web service request:

function clearSession() 

  var xmlVar = new XMLHttpRequest();  

  xmlVar .open("GET", "", false); 

  xmlVar .send(null);  


Yes, I named the service function name “Woohoo”.

And you’ll need a way to call your new function, so a button would be nice:

  <input type="button" id="btnClear" value="Clear Session" onclick="clearSession()" />

Finally, you’ll need a new Web Service file to the project called Service.asmx.  Inside the service file, add the best web service name ever:

 public void Woohoo()

So there you go.


Leave a comment

Posting ASP.NET page variables to another page

You know when you don’t do something for a long time, and even though it’s really simple, you completely forget how to do it? In this case, I just wanted to post a form from one ASP.NET page to another and view the resulting POST variables. Why? To impress the ladies.

On Page 1, I have this stunningly eloquent code:

<asp:TextBox ID=”txtValue1″ Text=”1″ runat=”server” />
<asp:TextBox ID=”txtValue2″ Text=”2″ runat=”server” />
<asp:TextBox ID=”txtValue3″ Text=”3″ runat=”server” />
<asp:Button ID=”btnSubmit” PostBackUrl=”~/Callbacks/PayPal.aspx” Text=”Submit” runat=”server” />

The important piece of information in that junk is the PostBackUrl property on the Button. That tells ASP.NET where to deliver your very important information, if that important information isn’t going to be on the same page.

And on Page 2, I have this equally eloquent code:

protected void Page_Load(object sender, EventArgs e)
string itemName = string.Empty;

for (int i = 0; i < Request.Form.Count – 1; i++)
itemName = Request.Form.AllKeys[i];
Response.Write(“<br />” + itemName + ” : ” + Request.Form.GetValues(i)[0]);

Feel free to use this code for all your important, top secret government and banking applications.

Leave a comment

Export a report in pipe-delimited format in Reporting Services

This is an extra special two-fer blog post – you get to see how to change a comma-delimited CSV file into a pipe-delimited file, and how to remove an extra space that was being included at the end of a pipe-delimited export. To accomplish these exciting things, I had to dive into the rsreportserver.config, a place I don’t like going, but somebody had to do the dirty work. In the DeviceInfo element, I added the “ExcelMode” element with a value of False:

      <Extension Name=”PIPE” Type=”Microsoft.ReportingServices.Rendering.DataRenderer.CsvReport,Microsoft.ReportingServices.DataRendering”>
                  <Name Language=”en-US”>CSV (PIPE Delimited)</Name>

You can also see how to create a pipe-delimited export, by creating a new “Extension” element. The “OverrideNames\Name” element contains the label that will appear when you click the Export button in Report Manager to see the list of options to export your file, such as Excel, PDF, and CSV. I changed the “FieldDelimiter” element to the pipe character, and the other fields are standard with the existing CSV export. With this knowledge, you’ll be the life of the party.

Leave a comment

Modifying Report Manager and the ReportViewer controls

Say the following line in that voice of the guy that announces monster truck rallies: 

Are you ready for code that is going to BLOW YOUR MIND???? 

Too bad, because you’re getting this instead.

I was tasked to make the Reporting Services ReportViewer control look the same as the one in Report Manager. The ReportViewer looked like this:



And reports in Report Manager looked like this:

Report Manager

Report Manager

Most of the work was done with ReportViewer, removing buttons or rearranging them. So in the code behind for the page that held the ReportViewer (and in the following code, “rvReport” is a Microsoft.Reporting.WinForms.ReportViewer control):

            ToolStrip toolStrip = (ToolStrip)rvReport.Controls.Find(“toolStrip1”, true)[0];

            ToolStripItem refresh = toolStrip.Items[10];
            ToolStripItem print = toolStrip.Items[12];
            ToolStripItem export = toolStrip.Items[15];

            for (int i = 0;i < 10; i++)
            toolStrip.Items.Insert(12, export);
            toolStrip.Items.Insert(13, refresh);
            toolStrip.Items.Insert(14, print);

What? What’s with calling RemoveAt(7) ten times? Well, there were ten controls that needed to be removed between the page navigation arrows on the left side of the ReportViewer and the zoom control. I know, it doesn’t look like there are ten, but there are.

But my important, life-changing work wasn’t done. No no, there was more fun to be had because the Atom feed button was still lurking on the Report Manager screen. So to get rid of that travesty, I had to change the Report Server configuration file, HtmlViewer.css. My file was located at C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer\Styles.

Track down the ToolbarAtomDataFeed style and change it’s display from inline to none:

 display: none;

You’re probably out of breath because of the non-stop excitement that was this post. But you can get a breather now, until the next awesome post. Enjoy the rest.