problem with PostBackUrl


C

Chris

Hi,

i created an ImageButton within an ItemTemplate of a datalist (in
shop.aspx). There are two possibilities:
1) when the user is logged and he clicks on an image, he must be
'postbacked' to another file showing that same picture in big size and with
more info..
2) when not logged and clicking on an image, he must be 'postbacked' to the
login page (log.aspx).

So i put the PostBackUrl property in code-behind like this:

Dim dl As DataList
Dim im As ImageButton
dl = form1.FindControl("DataList1")
im = dl.Items(0).FindControl("ImageButton1")
If User.Identity.IsAuthenticated Then
im.PostBackUrl = "Eval(""ProdNR"", ""prodItem.aspx?ProdNR={0}"")"
Else
im.PostBackUrl = "~/log.aspx"
End If

My double problem is:
1)when not logged, if i click on the first image, i'm postbacked to
log.aspx, but clicking on another image: nothing happens
2) when logged, if i click on the first image, i ger the error: "illegal
characters in path', and clicking on another image: same as 1): nothing
happens.

Any help would be appreciated.
Thanks
Chris
 
Ad

Advertisements

M

marss

Chris said:
Hi,

i created an ImageButton within an ItemTemplate of a datalist (in
shop.aspx). There are two possibilities:
1) when the user is logged and he clicks on an image, he must be
'postbacked' to another file showing that same picture in big size and with
more info..
2) when not logged and clicking on an image, he must be 'postbacked' to the
login page (log.aspx).

So i put the PostBackUrl property in code-behind like this:

Dim dl As DataList
Dim im As ImageButton
dl = form1.FindControl("DataList1")
im = dl.Items(0).FindControl("ImageButton1")
If User.Identity.IsAuthenticated Then
im.PostBackUrl = "Eval(""ProdNR"", ""prodItem.aspx?ProdNR={0}"")"
Else
im.PostBackUrl = "~/log.aspx"
End If

My double problem is:
1)when not logged, if i click on the first image, i'm postbacked to
log.aspx, but clicking on another image: nothing happens
2) when logged, if i click on the first image, i ger the error: "illegal
characters in path', and clicking on another image: same as 1): nothing
happens.

Any help would be appreciated.
Thanks
Chris

Hi,
It is incorrect syntax of Eval function use.
If you want to change template control at server side:
1.You can do it within OnItemDataBound event:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx
2.Wrap custom logic in the separate function:

aspx:
<asp:ImageButton ID="im" runat="server" PostBackUrl='<%#
GetUrl(Eval("ProdNR")) %>'/>

code:
Protected Function GetUrl(ByVal ProdNR As Object)
If User.Identity.IsAuthenticated Then
Return String.Format("~/prodItem.aspx?ProdNR={0}", ProdNR)
Else
Return "~/log.aspx"
End If
End Function

Maybe it helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top