|
heres the control ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProductListViewier.ascx.cs" Inherits="Controls_ProductListViewier" %>
<asp:DataList ID="dlProducts" runat="server" RepeatColumns="2" OnItemCommand="dlProducts_ItemCommand2">
<ItemTemplate>
<table style="padding:12px">
<tr>
<td>
<table>
<tr>
<td class="productdetail" colspan="2">
<%#DataBinder.Eval(Container.DataItem,"Name")%>
</td>
</tr>
<tr>
<td class="productdetailheading">
PRODUCT CODE:
</td>
<td class="productdetail">
<%#DataBinder.Eval(Container.DataItem, "ProductCode")%>
</td>
</tr>
<tr>
<td class="productdetailheading">
DISPOSE/ REUSE:
</td>
<td class="productdetail">
<%#DataBinder.Eval(Container.DataItem, "DisposeReuse")%>
</td>
</tr>
<tr>
<td class="productdetaillink" colspan="2">
<asp:LinkButton ID="btnShowProduct" runat="server" Text="Show Product Details" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "ProductID")%>' CommandName="ShowProductDetails" />
</td>
</tr>
</table>
</td>
<td>
<img alt="Image" style="height:100px; width:100px;" src="HttpHandlers/ImageHandler.ashx?productid=<%#DataBinder.Eval(Container.DataItem,"ProductID") %>"/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
and the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataLinq;
using BLL = BusinesLogic;
public partial class Controls_ProductListViewier : System.Web.UI.UserControl
{
private List<Product> _DisplayedProducts;
public List<Product> DisplayedProducts
{
get
{
return _DisplayedProducts;
}
set
{
_DisplayedProducts = value;
dlProducts.DataSource = _DisplayedProducts;
dlProducts.DataBind();
}
}
public delegate void ProductSelectHandler(Product product);
public event ProductSelectHandler ProductSelected;
private void OnProductSelected(Product product)
{
if (ProductSelected != null)
{
ProductSelected(product);
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void dlProducts_ItemCommand2(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "ShowProductDetails")
{
int selectedProductID = 0;
if (Int32.TryParse(e.CommandArgument.ToString(), out selectedProductID))
{
Product selectedProduct =
(from product in DisplayedProducts
where product.ProductID == selectedProductID
select product).Single();
OnProductSelected(selectedProduct);
}
}
}
}
The point is this works fine until i load the control dynamically into a place holder.
I want to use the same page (thats within a master page) to display the product listing, then when a product is selected the control publishes an event - the page receives this event, clears the place holder then displays the product details (loads a product display control into the holder)...
modified on Saturday, August 29, 2009 7:24 PM
|
|
|
|
|
Ok managed to find a fix...
The problem was that as the control was generated dynamically, on clicking on the link button the page would refresh, on its refresh the control was not created, so the link button didnt exist. I googled this for hours and the more I read about it the more I was told that its an EnableViewState issue (assuming enable view state would ensure the control exists after refreshes) - I enabled view state on the master page, the place holder on the master page, the page directive, the content holder on the page, the content holder that i populate dynamically, the user control, the data list within the control... still when the page refreshed the dynamically loaded content was always lost... any ideas on this?
Anyway to hack around this - when i set the datasource for the datalist i store it in a session parameter.
Then override OnInit on the page - and if the session parameter exists then recreate the control first. This has got it working but its a hack that I dont like.
|
|
|
|
|
I have already saw your code and it seemed to me fine. Yes, you need to EnableViewState when you want the control to appear during postbacks.
Chazzysb wrote: when i set the datasource for the datalist i store it in a session parameter
I suggest you to dont do that. Dont use Session to store datasource, as heavy data will eat up application pool memory. Rather
Use Fiddler to check what exactly the response generated. Check what exactly the problem is during the postbacks.
|
|
|
|
|
I have a site with fileupload control and some textboxes.
I want to collect data from these controls to a sql server(2005) connection.
Please Help me.
If anyone has an article please type that link.
|
|
|
|
|
Step One[^]
Step Two[^]
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
hey
i have a client that want me to show all his you tube movies on his personal site.
i need to get all the movies and display on a list .
when i user click a movie i need to display the movie on the client site.
maybe someone have a reference to guide ,how to do it ,or how to work with you tube...
|
|
|
|
|
This [^]can be a good place to start looking for some available API
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
|
thanx , will use the api!
|
|
|
|
|
That you have a 'client', and don't know how to use google, or search the site, is a disgrace.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I found that some javascript functions are requied to register first by using RegisterStartupScript in order to be used in ASP.net, however, some functions are not required for registration.
anyone can help me clarify what kind of javascript funcitons have to be registered?
|
|
|
|
|
Use RegisterStartupScript method to register the client script which needs to placed at the bottom of page. If you have events of controls are tied to client side scripts, then this could be useful.
As the control will not be availble at the page strtup, it's good to register them at the bottom.
Let me know if this helps you.
|
|
|
|
|
thanks, what do you mean the "bottom"?
|
|
|
|
|
Bottom means the lower section of the page.
Write some page, execute in borwser (e.g. IE) and try to check the view source.
|
|
|
|
|
Generally, before calling any javascript function, you need to add the source to the head element of the page using script tag. RegisterStartupScript just does this. It adds the script src to the page so that you can call it later.
Generally, Startup scripts which are added by ScriptManager is not required to be registered by yourself. As ASP.NET controls adds up those for you. But if you need some custom script to be added to your page, you can use this function.
|
|
|
|
|
In a web project under VS2008 team with some CSS file:
1) If the style is changed or another one applied the changes are visible from design view in VS2008
2) If the project gets published and you access it from IE as it is linked from IIS like http://localhost/WierdCSS[^] it is valid also
3) But when the project is being run from VS (using its ASP.NET Development Server http://localhost:29321/WierdCSS[^]) the styles become as they were from the very onset you created the style sheet file and once assigned its styles to web controls. Any following changes in the CSS do not take place in that case.
What is the problem with ASP.NET Development Server????
Чесноков
|
|
|
|
|
Are your CSS is within the App_THEME folder...
If so, you need to apply the Theme to the Site.
Another reason that might come in place, always add your files from root path specify like
~/css/myfile.css
not like
myfile.css (even if both are in same folder)
|
|
|
|
|
I do apply them, I enable them in page properties, and attach the CSS properly.
The glitch is with that particular project. Applying the same CSS in another project works perfect.
Can it be somehow spoiled in VS2008 for that particular project? Even after I removed css and changes are visible in design view, after running the page from VS it shows all styles, even site icon, though it was deleted from the web project.
I deleted all ASP.NET temporary files, nothing works.
Чесноков
|
|
|
|
|
Helo All,
I am using ASP.NET 3.5. I have a form with a DropDownList contain the User Code. At Selected Index Change the form shows the respecting data. But at times it shows the data but the following error Message is generate.
"Microsoft JScript runtime error: 'this.get_element().style' is null or not an object"
I am using master Page. There is an update panel in the master page.
How can i solve not to generate this error message when selected index change at DropDownList.
Thanks in advance
|
|
|
|
|
jahirhstu wrote: 'this.get_element().style' is null or not an object
It seems that you are trying to access the style before the element is initialized.
Can you debug by putting some alert in Javascript?
Do not know if this helps you much.
|
|
|
|
|
This is a Javascript error, where the element returns null.
I think if you set the autopostback of the Dropdownlist to false, the problem will be cured.
Or you can paste your designer code here to help you.
|
|
|
|
|
Hello
I want send a message from webesite to a local machine in network,
|
|
|
|
|
manish.m.meshram wrote: I want send a message from webesite to a local machine in network,
What do you mean by that ?
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
From my website I am sending Sql Query to a my local machine which is connected in a network , through router.
Thanks for you reply
|
|
|
|
|
manish.m.meshram wrote: I am sending Sql Query to a my local machine which is connected in a network
I am not sure what you exactly mean by "sending SQL Query to a my local machine".
But in general ADO.NET provides all the features using which websites generally interact with SQL Server.
You can take a look into this[^] (still I am sure you are not looking for this simple thing ).
Anyway,let me know if you need something more.
|
|
|
|