Thursday, August 21, 2008

RegisterForEventValidation can only be called during Render();

This error comes when you are exporting the GridView control from Visual Studio. To solve this error you have to turn the eventValidation off.  You can do this in the web.config file but if you do, the eventValidation will be turned off for all the pages.

<pages enableEventValidation ="false" ></pages>

Alternatively, you can do this in the Page directive which will turn off the validation for a single page.

<%@ Page Language="C#" EnableEventValidation = "false" AutoEventWireup="true"

CodeFile="ExportGridView.aspx.cs" Inherits="ExportGridView" %>

Monday, August 11, 2008

How to Drop a Column

  • Discover whether there is a constraint;

DECLARE @ConstraintName NVARCHAR(50);
SELECT @ConstraintName = [name]

FROM sys.objects o

WHERE o.[parent_object_id]=OBJECT_ID('Schema.TableName')

AND o.type='D'

AND o.[name] LIKE '%First5LettersOfColumnName%'

  • If there is, remove it;

IF NOT (@ConstraintName IS NULL)

   EXECUTE ('ALTER TABLE Schema.TableName 
   DROP CONSTRAINT ' + @ConstraintName)
GO

  • Remove the column

IF EXISTS(SELECT * FROM sys.columns WHERE [name]='ColumnName 
AND [object_id]=OBJECT_ID('Schema.TableName'))

      ALTER TABLE Schema.TableName

      DROP COLUMN ColumnName;

GO

Thursday, July 31, 2008

Emailing from a Web Page

Imports System.Net.Mail

'Create an instance of the MailMessage class
Dim objMM As New MailMessage()
Dim Requestor_DropDownList As DropDownList
Dim IssueID_Label As Label

With Issue_FormView   Requestor_DropDownList = .FindControl("RequestedBy_DropDownList")
   IssueID_Label = .FindControl("JobID_Label")
End With

'Set the properties
objMM.To.Add(Requestor_DropDownList.SelectedValue + "@telecom.co.nz")
objMM.From = New MailAddress("est@telecom.co.nz")

'Send the email in html format
objMM.IsBodyHtml = True

'Set the priority - options are High, Low, and Normal
objMM.Priority = MailPriority.Normal

'Set the subject
objMM.Subject = "Feedback"

'Set the body
Dim sb As New StringBuildersb.AppendLine("Kiaora " + Requestor_DropDownList.SelectedItem.Text)
sb.AppendLine()
sb.AppendLine("Your EST Issue is about to be closed.")
sb.AppendLine("Please take 5 minutes to rate the service you have received the the Enterprise Service Team.")
sb.AppendLine("Click into this link: http://wstProdIIS/EST/register/Issue.aspx?ID=" + IssueID_Label.Text)
objMM.Body = sb.ToString

'Now, to send the message, use the Send method of the SmtpClient class
Dim objSC = New SmtpClient
objSC.Host = "WNEXBE01.telecom.tcnz.net"
objSC.Send(objMM)

Wednesday, July 30, 2008

Some extra Reporting Service Parameters

<rsweb:ReportViewer ID="rptLetter" runat="server" ExportContentDisposition="AlwaysAttachment" 
       Height="475px" ProcessingMode="Remote" PromptAreaCollapsed="true"
       ShowPromptAreaButton="false" SizeToReportContent="True" Width="100%" ShowFindControls="false"
       BackColor="#ededed">
        <ServerReport ReportPath="/Reports/Letter" ReportServerUrl="https://reportserver" />
        </rsweb:ReportViewer>

  Dim MyDate As New ReportParameter("date", PrintDate)
  Dim p() As ReportParameter = {MyDate}

  rptLetter.ServerReport.ReportPath = "/Reports/" & ReportName
  rptLetter.ServerReport.ReportServerCredentials = New ReportViewerCredentials(
       "username", "password", "domain")
  rptLetter.ServerReport.SetParameters(p)
  rptLetter.ServerReport.Refresh()
  rptLetter.Visible = True

Wednesday, June 18, 2008

Eliminate Double-Lines from Table Borders

<table border=1 bordercolor="black" style="border-collapse:collapse">
   <tr>
      <td>
         Something clever goes in here
      </td>
   </tr>
   <tr>
      <td>
         Something smart goes in here
      </td>
   </tr>
</table>

Something clever goes in here
Something smart goes in here

Wednesday, June 11, 2008

[dotnet] MCPD upgrade exams from MCSD

Kiaora Shane, The greatest piece of advice I received was: don’t do it!  Do the individual exams instead.  When I attempted the 70-551, I failed.  Ended up doing all 3 exams separately (70-536, 70-528, 70-547).  Greater coverage, greater understanding.  Unless you’re a genius.  For those of us of average intelligence, not a good choice.


From: dotnet@dot.net.nz [mailto:dotnet@dot.net.nz] On Behalf Of s ~
Sent: Tuesday, 10 June 2008 4:42 p.m.
To: dotnet@dot.net.nz
Subject: [dotnet] MCPD upgrade exams from MCSD

Fellas,

has anyone sat either of exams 70-553 or 70-554? If so, do you have any study material you can sell second hand, or can you point me towards some study material? There are guides and practice exams available for the other regular exams in the MCPD range, but there seems to be a scarcity of anything for the upgrade exams.

cheers

shane

Sunday, June 8, 2008

When 2 grids are linked

When you have:

  • a web page
  • 2 DataGridViews (parent/child relationship)
  • user wants to insert a new record into parent grid
  • parent grid has datasource set to Nothing so that EmptyDataTemplate shows
  • EmptyDataTemplate contains a DetailView
  • user fills in fields and clicks Insert
Then you get:
  • the parent record saves correctly; and
  • the page refreshes; but 
  • an error occurs because the child grid is linked to an empty Parent grid.
  • No amount of fiddling with the SelectedItem property of the Parent grid seems to work.

Resolution:

  • Hide the second grid until the user manually makes a selection on the Parent grid.