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

Monday, March 26, 2012

Server tag not well formed

This thing always gets me.

onclick="DisplayExamMessage('<%# Eval("Description") %>')"

Any ideas!

What is the onclick coming from? A Button or a picture?


Its a asp.net hyperlink control.

<asp:HyperLink id="hlDescription" onclick="DisplayExamMessage()" NavigateUrl="#" Text="Read Description" runat="server"> </asp:HyperLink

Try

onclick=<%# DisplayExamMessage(Eval("Description").ToString()) %>


Hi,

But DisplayExamMessage is a JavaScript function.

onclick=<%# DisplayExamMessage(Eval("Description").ToString()) %>

Function DisplayExamMessage(ByVal t As String)

Return "DisplayExamMessage('" & t & "');"
End Function

Ugly but should work


I see.

Add DisplayExamMessage() to your server script. Then, do this:

protected string DisplayExamMessage(string descrition)
{
if(descrition.Trim().Length != 0)
return "javascript:DisplayExamMessage(" + descrition + ");"; //I use same name for your

//server script and javascript. You can use different name

else
return string.Empty;
}

Server tage not well formed

Hello,
Can anyone tell me if this is possible. If yes then can you identify the error in this line. I am writing this line of code in .aspx file in VB.NET v1.1

<asp:Image id="productImage" runat="server" ImageUrl="<%# ConfigurationSettings.AppSettings("virtualdir") & DataBinder.Eval(Container.DataItem,"WebImageName")%>"></asp:Image>

The error says server tag not well formed.

Thanks

I would create a variable (string), to concatenate this:
ConfigurationSettings.AppSettings("virtualdir") & DataBinder.Eval(Container.DataItem,"WebImageName")

Dim sPath as string
sPath=ConfigurationSettings.AppSettings("virtualdir") & WebImageName ' (substitute WebImageName with however you retrieve this-like datareader/dataset...

Then, in your ImageURL:
ImageURL='<%# sPath %>'


Thanks for the help... But how can i write a fuction in the server tag. Do i need to write it seperately and make be call that function, if so can u say how can i do that.

Thanks Again.


It is a better idea if you use a method in the code behind to use the concatenation.

protected string FormatPath(string webImageName)
{
string virtualDirectory = (string) ConfigurationSettings.AppSettings["virtualdir"];
return virtualDirectory + webImageName;
}

Hope this helps!
I forgot you need to add something like this also:

<asp:Image id="productImage" runat="server" ImageUrl='<%# (string) FormatPath(DataBinder.Eval("Container.DataItem","webImageUrl") %>' "></asp:Image

Server tag not well formed error.

I have created a custom image control everything works fine. It renders in the browser fine.

But when I drop the control in the webform, set the properties, go to html view, then back to design view. I get a gray box where my custom control was that says "Error Creating Custom Control" and then a message of "Server Tag is not well formed".

Anyone know why this would happen?
Here is how it looks in HMTL view from within the IDE.

<JHA:JHAImageRollover id="JHAImageRollover1" onclick="http://www.google.com" runat="server" BaseImage="/common/images/btn_search.gif" RolloverImage="/common/images/btn_cancel.gif"></JHA:JHAImageRollover>Is there are <@.Register > tag on the top of the .aspx page that the control is on?

My guess is the page doesn't know anything about the control since its library is not registered with the page.

<%@. Register TagPrefix="jh1" Namespace="YourControlLibraryNamespace" Assembly="YourControlLibrary" %>
Got it fixed...strange though.

The TagPrefix in the page directive was "jha"
it was yelling because the control had "JHA"

go figure!?