dimanche 1 juin 2014

do a post back when a message from SignalR package receive


Vote count:

0




I have two nested gridView in my page , first gridView is for showing Posts and another for comments, I used SignalR package, when a user post new comment a message will be send to all other clients to update their GridView ! but now i dont know how update my gridview when new message is received ! i tried to do a postback with a hidden button but it dosent workS here is my codes ! please help to update my GridViews thnaks !


( i tried the SignalR is working )



<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:GridView ID="post" runat="server" AutoGenerateColumns="false"
DataKeyNames="postID" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Text") %>' ></asp:Label>
<asp:Label ID="like" runat="server" Text='<%# Bind("number_of_likes") %>'></asp:Label>
<asp:Panel ID="pnlOrders" runat="server">

<asp:GridView ID="comments" ShowHeader="false" runat="server" AutoGenerateColumns="false">
<Columns >
<asp:TemplateField ShowHeader="false">
<ItemTemplate >
<asp:Label ID="Label2" runat="server" Text='<%# Bind("SenderName") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ContentTemplate>
<Triggers>

<asp:AsyncPostBackTrigger ControlID="ReloadThePanel" EventName="Click" />

</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" Text="" runat="server"></asp:TextBox>
<asp:Button ID="Button1" OnClick="Button1_Click" runat="server" Text="Comment" />
</ContentTemplate>
<Triggers>

<asp:AsyncPostBackTrigger ControlID="ReloadThePanel" EventName="Click" />

</Triggers>
</asp:UpdatePanel>

</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


scripts



<script type="text/javascript">
$(function () {
var chat = $.connection.chatHub;
chat.client.broadcastMessage = function () {
__doPostBack('<%=ReloadThePanel.ClientID %>', '');
// i should rebind or make post back here
};

$.connection.hub.start().done(function () {

});
});
</script>


code behind



protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
post.DataSource = GetData();
post.DataBind();
}

}


protected void Button1_Click(object sender, EventArgs e)
{

ChatHub.Send();
}


asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire