Showing posts with label formed. Show all posts
Showing posts with label formed. Show all posts

Saturday, March 24, 2012

Tag not well formed?

I keep getting a "Parser Error Message:The server tag is not well formed" message for this. Can anyone help me understand why?

<asp:SqlDataSource ID="ctrlDataSource" runat="server"
ProviderName="System.Data.OleDb"
ConnectionString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("Database\TestDB.mdb")
Set DbConnection = Server.CreateObject("ADODB.Connection")
DbConnection.Open ConnectionString
SelectCommand="SELECT * FROM [Testtable] WHERE ID=@dotnet.itags.org.id" >

Is it the &? or Server.MapPath(@."Database\TestDB.mdb") ?


I don't think it is the &. I've seen it in sample code that uses Server.MapPath as part of the connectionstring. However, if not for the &, how would I make the Server.MapPath part of ConnectionString?

g2000:

or Server.MapPath(@."Database\TestDB.mdb") ?


I'm not sure what you mean...that there should be @. ?


doesn't it need the closing /

... /> instead of ...>


Actually, I close the tag later on, after SelectParameters. More completely, it looks like this:

<asp:SqlDataSource ID="ctrlDataSource" runat="server"
ProviderName="System.Data.OleDb"
ConnectionString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("Database\TestDB.mdb")
Set DbConnection = Server.CreateObject("ADODB.Connection")
DbConnection.Open ConnectionString
SelectCommand="SELECT * FROM [Testtable] WHERE ID=@.id"
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" />
</SelectParameters
</asp:sqldatasource


have you tried hard-coding the conn string, as a test?


Yes. I used

<asp:SqlDataSource ID="ctrlDataSource" runat="server"
ProviderName="System.Data.OleDb"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=e:\ectserver\abcuser\DataBase\Testdb.mdb"
SelectCommand="SELECT * FROM [Testtable] WHERE ID=@.id" >

Now that is a bogus path, because I don't know the real one (this is not my server). However, the error message I get back is "is not a valid path," which is what I wouldexpect since it's bogus. It no longer complains"tag is not well formed." So why is the hard-coded tag well-formed while the other one isn't? I think there must be something about the syntax of my original <asp:SqlDataSource> ?


I don't think SqlDataSource has properties like

Set DbConnection = Server.CreateObject("ADODB.Connection")
DbConnection.Open ConnectionString

I am just beginning with ASP.NET but i think you would have to use <%= Server.MapPath("Database\TestDB.mdb") %>


I don't think you can concatenate a connection string within the SqlDataSource tag.

Try creating a connection string and assigning it to the data source programmatically in your code-behind page.



Ted C:

Try creating a connection string and assigning it to the data source programmatically in your code-behind page.

OK. How would I do this?


While lookking for the exact answer to your question, I found how to set up your connection string in your Web.config file. You'd have the following as part of the Web.config...

<connectionStrings>
<add name="SqlConnectionString"
connectionString="Data Source=localhost\band;Initial Catalog=Players;
Persist Security Info=True;User ID=band;Password=letmein"
providerName="System.Data.SqlClient"/>
</connectionStrings>

... and then your SqlDataSource tag would look something like...

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SqlConnectionString %>"
SelectCommand="SELECT [PlayerName], [PlayerManufacturerID] FROM [Player]">
</asp:SqlDataSource>

EDIT: Except I don't know if that solves your problem of dynamically building the connection string...

More searching...


OK, ConnectionString is a property of the SqlDataSource object, so you first create a string variable and use it to build your connection string dynamically...

string myConnString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("Database\TestDB.mdb");

...then you assign that string to the SqlDataSource's ConnectionString property...

SqlDataSource1.ConnectionString = myConnString;

You might even be able to do it in one line in the code-behind page.

SqlDataSource1.ConnectionString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("Database\TestDB.mdb");

That's in C#, of course. You'd need to translate it into VB, if that's what you're using.


Ted C:

OK, ConnectionString is a property of the SqlDataSource object, so you first create a string variable and use it to build your connection string dynamically...

string myConnString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("Database\TestDB.mdb");

...then you assign that string to the SqlDataSource's ConnectionString property...

SqlDataSource1.ConnectionString = myConnString;

I tried that a little earlier, when you first suggested that maybe I could not concatenate within the tag. I tried

<%

string cstr = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("TestDB.mdb");

SqlDataSource.ConnectionString = cstr;

%>

I also tried single-line. But I kept getting back the error "CS0120:An object reference is required for the nonstatic field, method, orproperty 'System.Web.UI.WebControls.SqlDataSource.ConnectionString.get'" which is why I wound up asking how do I do it...I am not familiar with this error?


Although OLEDB can be used with SQLDATASOURCE, however why not use AccessDataSource which is built for this purpose. Actually it inherits from sqldatasource.

An example

<asp:AccessDataSource id="InvoiceAccessDataSource" DataFile="~/App_Data/Northwind.mdb" runat="server" SelectCommand="[Employee Sales By Country]" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:Parameter Name="Beginning Date" Type="DateTime" defaultValue="1/1/1997" /> <asp:Parameter Name="Ending Date" Type="DateTime" defaultValue="1/31/1997" /> </SelectParameters></asp:AccessDataSource><asp:GridView id="InvoiceGridView" runat="server" AutoGenerateColumns="True" DataSourceid="InvoiceAccessDataSource" />
http://msdn2.microsoft.com/en-us/library/8e5545e1.aspx
Should you wish to continue using Sql datasource then here is how to do it.
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html > <head runat="server"> <title>ASP.NET Example</title></head><body> <form id="form1" runat="server"> <asp:SqlDataSource id="SqlDataSource1" runat="server" DataSourceMode="DataReader" ConnectionString="<%$ ConnectionStrings:MyNorthwind%>" SelectCommand="SELECT LastName FROM Employees"> </asp:SqlDataSource> <asp:ListBox id="ListBox1" runat="server" DataTextField="LastName" DataSourceID="SqlDataSource1"> </asp:ListBox> </form> </body></html>
http://msdn2.microsoft.com/en-us/library/dz12d98w(vs.80).aspx
 
Hope that helps, please ping with any questions

tag not well formed with java and quotes problem

Here is the tag:

<asp:Image ID="Photo" runat="server" ImageUrl="Images/Loading.gif" OnLoad="SwapImage(this,'Handler.ashx?AlbumID=<%#Eval("AlbumID")%>&Size=M');" CssClass="photo_198" style="border:4px solid white" ToolTip='<%#Eval("DESCRIPTION")%>' />

I know the problem is something with the OnLoad part of the tag. and I'm pretty sure it has to do with the single quotes around the handler url. can anyone help with this? do I need to escape out of the single quote or what?

Try this

<asp:Image ID="Photo" runat="server" ImageUrl="Images/Loading.gif" OnLoad='SwapImage(this,<%# "Handler.ashx?AlbumID=" & Eval("AlbumID")%>&"Size=M");' CssClass="photo_198" style="border:4px solid white" ToolTip='<%#Eval("DESCRIPTION")%>' />
I dont have the swapImage function, so I'm not sure if it's working or not, but the error changed :)

onmouseover="<%#"javascript:clearHistory1('" & Eval("Heading") & "','" & Eval("Description") & "');"%>"


niether of those two helped, the 2nd on gives a worse error and I'm not doing a roll over image. Here is my swapImage function

 <script type="text/javascript"> function SwapImage(img,src) { img.src=src; } </script>

this is what I changed the onload part to and still get the not well formed tag error:

<asp:Image ID="Photo" runat="server" ImageUrl="Images/Loading.gif" OnLoad='<%#"SwapImage(this, 'Handler.ashx?AlbumID=" + Eval("AlbumID") +"&Size=M')"%>' CssClass="photo_198" style="border:4px solid white" ToolTip='<%#Eval("DESCRIPTION")%>' />

ASP:Image is a server side control, when you specify the onload event, it's looking for a server onload event, not a JavaScript event which is client side.

<imgonload="SwapImage(this,<%# "handler.ashx?AlbumID=" & Eval("AlbumID") & "&Size=M" %>);"src="Images/loading.gif"class="photo_198"style="border:4px solid white"ToolTip='<%#Eval("Description")%>'/>

You need a client side HTML tag like above, who's onload even will fire on the client side, not the server side.

Hope this helps.


here is the other way is wrote the Onload part and got the same error:

OnLoad="SwapImage(this, 'Handler.ashx?AlbumID=<%# Eval("AlbumID") %>&Size=M')"


thanks a lot!!! It works great! I just needed to change the onload function in the swapImage function


it looks great in firefox but in IE 7.0 the animation of the loading gif never animates and just shows the first frame. The actual image load above it, but IE says there is an error on the page and says the error is "Error: object expected"


I fixed the Error but in IE I still don't get any animation from the loading.gif, anyone know why?


It's almost assurendly a problem with your handler. Can you post the code to the handler you're using to retreive the image?


the handler returns the correct image fine. The website runs perfect with animation in firefox but IE 7.0 just stops the animation of the loading.gif at the first frame