B
Bjorn Sagbakken
I am porting my digital photo archive from a windows app to web using ASP.NET 2.0
- The search options is contained within one UpdatePanel
- The result, a filmstrip of thumnails(ImageButton) in a repeater is contained within a scrollable Panel within another UpdatePanel
- The view of a large image (on clicking on the thumnail) is contained within yet another UpdatePanel
All this works kind of nice, except a couple of minor issues that made me re-think a bit.
a) Clicking on a thumnail a bit down the list makes the list regenerate, showing the images at the top
b) When the search result is like 100 images or more there is a noticable delay at each click on the list.
Sure, this is because the whole list is included in the partial postback. I have tried to encapsulate each image in a separate UpdatePanel, but for some reason the compiler doesn't like this. Here is the portion where I try to insert a separate UpdatePanel for each image. The <td> is the cell in the ItemTemplate of a repeater.
<td align="center" style="background-color:Transparent">
<asp:UpdatePanel runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:ImageButton runat="server" OnClientClick="Image_Click(this);" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>' BorderStyle="None" BorderWidth="0" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "Image") %>'/>
</ContentTemplate>
</asp:UpdatePanel>
</td>
The error message is:
Error 21 'System.Web.UI.Control' does not contain a definition for 'DataItem'
Question 1: Any idea why this happens?
Next, I thought of a bit different approach. I replaced the ImageButton with a Image (asp or html). The filmstrip of thumnails still show very well. But now I have the challenge of showing the large image on client click. Detecting which image is clicked via java-script is easy, but I also need to return to the server, retrieve tha large image from the SQL server and refresh the UpdatePanel containing the large image. As I understand this should be fairly easy using the Client Callback feature in ASP.NET 2.0 I have read some articles I have found on the net, copied the code and tried various settings. Nevertheless, I always get a client script error: "Object expected"
I am not sure which object...
Here is the client sript I am testing:
function Image_Click(ID)
{
UseCallBack();
}
function JSCallback(ReturnValue, context)
{
document.getElementById("Textbox1").value=ReturnValue;
}
And here is the server code:
public partial class _Default :
System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
#region ICallbackEventHandler Members
string callbackresult;
protected void Page_Load(object sender, EventArgs e)
{
// get reference of call back method named JSCallback
string cbref = Page.ClientScript.GetCallbackEventReference(this, "arg", "JSCallback", "context");
// Generate JS method trigger callback
string cbScr = string.Format("function UseCallBack(arg, context) {{ {0}; }} ", cbref);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallBack", cbScr, true);
}
public string GetCallbackResult()
{
return callbackresult;
}
public void RaiseCallbackEvent(string strID)
{
int ID = Convert.ToInt32(strID);
callbackresult = "Ok: "+ID.ToString();
}
#endregion
}
Question 2: Any idea why this doesn't work?
Question 3: Is the Client Callback the best approach for this task? Any good examples to study?
Thanks.
Bjorn
- The search options is contained within one UpdatePanel
- The result, a filmstrip of thumnails(ImageButton) in a repeater is contained within a scrollable Panel within another UpdatePanel
- The view of a large image (on clicking on the thumnail) is contained within yet another UpdatePanel
All this works kind of nice, except a couple of minor issues that made me re-think a bit.
a) Clicking on a thumnail a bit down the list makes the list regenerate, showing the images at the top
b) When the search result is like 100 images or more there is a noticable delay at each click on the list.
Sure, this is because the whole list is included in the partial postback. I have tried to encapsulate each image in a separate UpdatePanel, but for some reason the compiler doesn't like this. Here is the portion where I try to insert a separate UpdatePanel for each image. The <td> is the cell in the ItemTemplate of a repeater.
<td align="center" style="background-color:Transparent">
<asp:UpdatePanel runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:ImageButton runat="server" OnClientClick="Image_Click(this);" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>' BorderStyle="None" BorderWidth="0" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "Image") %>'/>
</ContentTemplate>
</asp:UpdatePanel>
</td>
The error message is:
Error 21 'System.Web.UI.Control' does not contain a definition for 'DataItem'
Question 1: Any idea why this happens?
Next, I thought of a bit different approach. I replaced the ImageButton with a Image (asp or html). The filmstrip of thumnails still show very well. But now I have the challenge of showing the large image on client click. Detecting which image is clicked via java-script is easy, but I also need to return to the server, retrieve tha large image from the SQL server and refresh the UpdatePanel containing the large image. As I understand this should be fairly easy using the Client Callback feature in ASP.NET 2.0 I have read some articles I have found on the net, copied the code and tried various settings. Nevertheless, I always get a client script error: "Object expected"
I am not sure which object...
Here is the client sript I am testing:
function Image_Click(ID)
{
UseCallBack();
}
function JSCallback(ReturnValue, context)
{
document.getElementById("Textbox1").value=ReturnValue;
}
And here is the server code:
public partial class _Default :
System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
#region ICallbackEventHandler Members
string callbackresult;
protected void Page_Load(object sender, EventArgs e)
{
// get reference of call back method named JSCallback
string cbref = Page.ClientScript.GetCallbackEventReference(this, "arg", "JSCallback", "context");
// Generate JS method trigger callback
string cbScr = string.Format("function UseCallBack(arg, context) {{ {0}; }} ", cbref);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallBack", cbScr, true);
}
public string GetCallbackResult()
{
return callbackresult;
}
public void RaiseCallbackEvent(string strID)
{
int ID = Convert.ToInt32(strID);
callbackresult = "Ok: "+ID.ToString();
}
#endregion
}
Question 2: Any idea why this doesn't work?
Question 3: Is the Client Callback the best approach for this task? Any good examples to study?
Thanks.
Bjorn