Showing posts with label below. Show all posts
Showing posts with label below. Show all posts

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.

Wednesday, March 21, 2012

Delegates on succes webservice call

Hi All,

I am writing a control where i would like to refer to a method inside my own control, see code below to make the situation clear:

var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false,null,this.WebserviceCallCompleted,this.WebserviceCallFailed,null, 10000);

First i do a webservice call which is working great! As you can see when the call succeeds the function WebserviceCallCompleted is invoked. In this method i would like to set a variable and start the rendering proces again. I do this with:this.Render;

WebserviceCallCompleted:function(result)

{

this._buttonText = result;

this.Render;

}

When i run this code the Render method isn't invoked. any ideas? should i use delegates?

Thanks in advance!

Regards,

To Resolve the this keyword use Function.createDelegate. Like:

var successHandler = Function.createDelegate(this, this.WebserviceCallCompleted);

var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false,null,successHandler,this.WebserviceCallFailed,null, 10000);


Hi KaziManzurRashid,

Thanks for your reply. I implemented your solution but it isn't working (yet) below you see what i have done:

InvokeWebservice:function()

{

var _completeHandler = Function.createDelegate(this,this.WebserviceCallCompleted);var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false, {"test":$get('txtfld1').value}, _completeHandler,this.WebserviceCallFailed,null, 10000);

}

,

WebserviceCallCompleted:function(result)

{

this.Render;

}

The WebserviceCallCompleted method is invoked so the delegate is implemented right. When i take a closer look at the this instance is see that 'this' is representing the right control and it contains a Render method but it still isn't invoked. Any idea?

Regards,


I could not find any reason the Render is not get executed, may be you should put this.Render() instead of this.Render.


hi KaziManzurRashid,

Very stupid but thats the trick i changed this.Render in this.Render() and it works. Probably there is a difference when you refer to a method when creating a delegate and when refering directly to it. I feel a little stupid! Thanks for your time and solutionBig Smile

Regards,

Defining 2nd Autocomplete Textbox

How would you define a second autocomplete textbox? Below is how I did it and I have two seperate div tags for the drop downs.
Seems like the memory isn't cleared or something like that because the second drop always seems to call the first drop downs method or at least produce a list as if it called the first drop downs method.

<scripttype="text/xml-script">

<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

<references>
<add src="ScriptLibrary/AtlasUI.js" />
<add src="ScriptLibrary/AtlasControls.js" />
</references>
<components>
<textBox id="SearchKey">
<behaviors>
<autoComplete
completionList="completionList"
serviceURL="AutoCompleteService.asmx"
serviceMethod="GetWordList1"
minimumPrefixLength="2"
completionSetCount="15"
completionInterval="500" />
</behaviors>
</textBox>

<textBox id="SearchKey1">
<behaviors>
<autoComplete
completionList="completionList1"
serviceURL="AutoCompleteService.asmx"
serviceMethod="GetAppList"
minimumPrefixLength="2"
completionSetCount="15"
completionInterval="500" />
</behaviors>
</textBox>
</components>

</page>

</script>
Thanks for any help,
Clank

On top in the Web Service code, find this line..

privatestaticstring[] autoCompleteWordList =null;


I guess u must be storing the 2nd result also in this same member. Change this to

privatestring[] autoCompleteWordList =null;

It should work now.
Thanks, that fixed my problem.