Workaround for VBScript “Invalid Character” error in ASP.NET 2.0

A block of VBScript in ASP.NET page works fine to print barcode  in ASP.NET 1.1, but the code generates  "Invalid Character" error when upgraded to ASP.NET 2.0. By adding an extra empty javascript block before the vbscript block can get rid of this error.

<head runat="server">
    <title>MyPage</title> <script type="text/javascript"></script>

    <script type="text/vbscript">……</script>
</head>

This tip was found from this thread: http://forums.asp.net/t/1149127.aspx

Thanks, Benson Yu, for sharing.

Advertisements

Filter gridview through a dropdownlist in the headertemplate

<asp:GridView ID="GV_Buildings" runat="server" AutoGenerateColumns="False" DataKeyNames="building_id"
            DataSourceID="SqlDataSource1" OnDataBound="GV_Buildings_DataBound">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="building_id" HeaderText="building_id" ReadOnly="True"
                    SortExpression="building_id" />
                <asp:BoundField DataField="building_name" HeaderText="building_name" SortExpression="building_name" />
                <asp:TemplateField SortExpression="is_school">
                <HeaderTemplate>
                                <asp:DropDownList ID="DDL_BuildingsIsSchool" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DDL_BuildingsIsSchool_OnSelectedIndexChanged">

                                    <asp:ListItem Selected="True" Value="">All Buildings</asp:ListItem>

                                    <asp:ListItem Value="1">Schools</asp:ListItem>

                                    <asp:ListItem Value="0">Other Buildings</asp:ListItem>

                                </asp:DropDownList>

                            </HeaderTemplate>


                    <EditItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("is_school") %>' />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("is_school") %>' Enabled="false" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
            DeleteCommand="DELETE FROM [buildings] WHERE [building_id] = @building_id" InsertCommand="INSERT INTO [buildings] ([building_id], [building_name], [is_school]) VALUES (@building_id, @building_name, @is_school)"
            SelectCommand="SELECT [building_id], [building_name], [is_school] FROM [buildings] WHERE is_school=ISNULL(@is_school,is_School)"
            UpdateCommand="UPDATE [buildings] SET [building_name] = @building_name, [is_school] = @is_school WHERE [building_id] = @building_id" 
            CancelSelectOnNullParameter="false">
            <DeleteParameters>
                <asp:Parameter Name="building_id" Type="Int32" />
            </DeleteParameters>
     <SelectParameters>
      <asp:Parameter Name="is_school" />
    </SelectParameters>
      <UpdateParameters>
                <asp:Parameter Name="building_name" Type="String" />
                <asp:Parameter Name="is_school" Type="Boolean" />
                <asp:Parameter Name="building_id" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="building_id" Type="Int32" />
                <asp:Parameter Name="building_name" Type="String" />
                <asp:Parameter Name="is_school" Type="Boolean" />
            </InsertParameters>
        </asp:SqlDataSource>
    

  

protected void GV_Buildings_DataBound(object sender, EventArgs e)
    {
      
        if (!IsPostBack)
        {
         DropDownList ddl_building =(DropDownList)GV_Buildings.HeaderRow.FindControl("DDL_BuildingsIsSchool");
         SqlDataSource1.SelectParameters["is_School"].DefaultValue = ddl_building.SelectedValue;

        }
    }


    protected void DDL_BuildingsIsSchool_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl_building= (DropDownList)sender;
       SqlDataSource1.SelectParameters["is_School"].DefaultValue = ddl_building.SelectedValue;

    }