Showing posts with label individual. Show all posts
Showing posts with label individual. Show all posts

Wednesday, March 28, 2012

Different instances of beginRequest & endRequest for different UpdatePanels

Is it possible to assign a different beginRequest function or endRequest function for individual UpdatePanels on a page? It appears that usingSys.WebForms.PageRequestManager.getInstance().add_beginRequest( someFunction ) assign the function to all UpdatePanels on the page.

Thank you

yeah, check this out...

http://dotnetslackers.com/community/blogs/simoneb/archive/2006/11/19/ASP.NET-Ajax-UpdatePanelNotifier_3A00_-get-notified-of-partial-updates.aspx


i have looked into alittle more.

<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args)
{
var elem = args.get_postBackElement();
//What Triggered The Update
//alert(elem.id);
}
function EndRequestHandler(sender, args)
{
var s = args.get_response().get_responseData().split('|');
//UpdatePanel Triggered
alert(s[2]);
}
</script>


Thanks for the response. So there is currently no 'native' way do do this? Surprising. I'll check out this project.

Thanks again.


Interesting... It still would be nice to have a native way of assigning functions to different panels, but this could certainly be of use in certain circumstances.

Thanks!

Monday, March 26, 2012

Detailsview ItemUpdate Event with UpdatePanel

I have a grid with individuals in it, the user selects and individual which populates a Detailsview below. Both gridview and Detailsview are wrapped with UpdatePanels. The user can then edit the individual in the Detailsview and submit changes when updateing. Now the updatepanel wrapping the gridview has an <asp:AsyncPostBackTrigger tied back to the Detailsview's ItemUpdated event.

I ultimately want the grid of selected individuals to update whenever the user makes changes to the individuals through the supporting gridview, the trigger I am using is not providing the functionality I am looking for, what approach should I take next? or is this trigger not working properly?

I can provide code-snippets, but figured it would be better to get a high level overview then look at some of my mess :)

Thanks in advance to anyone who offers help.

Here are some sample codes for your reference.
.ASPX
<div>
<asp:UpdatePanel ID="gvUpnl" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvProduct" runat="server" AutoGenerateSelectButton="true" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" DataKeyNames="ProductID" DataSourceID="sqlDS" OnRowCommand="gvProduct_RowCommand">
<Columns>
<asp:TemplateField HeaderText="ProductID" SortExpression="ProductID">
<ItemTemplate>
<asp:Label ID="lblProductID" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
<asp:BoundField DataField="TransactionDate" HeaderText="TransactionDate" ReadOnly="True"
SortExpression="TransactionDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:ProductConnectionString %>" DeleteCommand="DELETE FROM [Product] WHERE [ProductID] = @.ProductID" InsertCommand="INSERT INTO [Product] ([ProductName], [UnitPrice], [Quantity], [TransactionDate]) VALUES (@.ProductName, @.UnitPrice, @.Quantity, @.TransactionDate)" SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice], [Quantity], [TransactionDate] FROM [Product]" UpdateCommand="UPDATE [Product] SET [ProductName] = @.ProductName, [UnitPrice] = @.UnitPrice, [Quantity] = @.Quantity, [TransactionDate] = @.TransactionDate WHERE [ProductID] = @.ProductID">
<DeleteParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Double" />
<asp:Parameter Name="Quantity" Type="Int32" />
<asp:Parameter Name="TransactionDate" Type="DateTime" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Double" />
<asp:Parameter Name="Quantity" Type="Int32" />
<asp:Parameter Name="TransactionDate" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvProduct" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="dvUpnl" runat="server">
<ContentTemplate>
<asp:DetailsView ID="dvProduct" runat="server" DataKeyNames="ProductID" AllowPaging="True" DataSourceID="dvDS" AutoGenerateEditButton="true" AutoGenerateInsertButton="true" AutoGenerateDeleteButton="true">
</asp:DetailsView>
<asp:SqlDataSource ID="dvDS" runat="server" ConnectionString="<%$ ConnectionStrings:ProductConnectionString %>">
<SelectParameters>
<asp:Parameter Name="ProductID" Type="Int32" Direction="Input" DefaultValue="1"/>
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ProductID" Type="Int32" Direction="Input" />
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="UnitPrice" Type="double" />
<asp:Parameter Name="Quantity" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</div
Behind Code:
protected void Page_Load(object sender, EventArgs e)
{
string cString = System.Configuration.ConfigurationManager.AppSettings["ProductConnectionString"];
dvDS.ConnectionString = cString;
dvDS.SelectCommand = "SELECT ProductID,ProductName,UnitPrice,Quantity,TransactionDate FROM Product WHERE ProductID=@.ProductID";
dvDS.UpdateCommand = "UPDATE Product SET ProductName=@.ProductName,UnitPrice=@.UnitPrice,Quantity=@.Quantity WHERE ProductID=@.ProductID";
}

protected void gvProduct_RowCommand(object sender, GridViewCommandEventArgs e)
{
Label lblProductID = gvProduct.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("lblProductID") as Label;
string productID = lblProductID.Text;
if(e.CommandName == "Select")
{
dvDS.SelectParameters["ProductID"].DefaultValue = productID;
}
else if(e.CommandName == "Edit")
{}
else if(e.CommandName == "Delete")
{}
}
Wish the above can help you.