<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ChatUserControl.ascx.cs"
Inherits="MetamorphismApp.ChatUserControl" %>
<asp:Timer ID="timer1" runat="server" OnTick="timer1_Tick" Interval="5000">
</asp:Timer>
<div id="divChatWindow" class="clChatWindow">
<div>
<asp:Label runat="server" Text='<%# Eval("username") %>' class="divHeader" ID="lblChatFriend"></asp:Label>
<asp:Image ID="imgFriend" runat="server" CssClass="classFriendImage" />
<asp:LinkButton ID="lbClose" runat="server" CommandName="Close" CssClass="lbClose"
OnClick="lbClose_Click">Close</asp:LinkButton></div>
<div class="chatText" id="idChatText" runat="server">
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="Tick" />
<asp:AsyncPostBackTrigger ControlID="btnSendChat" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Repeater runat="server" ID="rpChatMessages">
<ItemTemplate>
<asp:Image ID="imageForFriend" runat="server" CssClass="clFriendsImage" ImageUrl='<%# "HttpImageHandler.jpg?username=" + DataBinder.Eval(Container.DataItem,"fromusername").ToString() %>' />
<asp:Label ID="chatMessage" runat="server" Text='<%# Eval("Message") %>'></asp:Label>
<br>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:TextBox ID="txtChatMessage" runat="server" Width="142px" CssClass="clChatMessage" EnableViewState="true"
TextMode="MultiLine"></asp:TextBox>
<asp:LinkButton ID="btnSendChat" runat="server" CommandName="Insert" CommandArgument='<%# Eval("username") %>'
OnClick="btnSendChat_Click">Send</asp:LinkButton>
</div>
protected void btnSendChat_Click(object sender, EventArgs e)
{
string username = lblChatFriend.Text;
ucc.InsertMessage(Session["username"].ToString(), username, txtChatMessage.Text);
txtChatMessage.Text = "";
}
txtChatMessage does not become blank when btnSendChat_Click event handler is called
Try this:
txtChatMessage.Text = string.Empty;
to make sure that the text is null or empty
Related
lblEmail.Text=dt.Rows[0]["Email"].ToString();
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="2" Width="256px" ForeColor="Blue" Height="250px">
<cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Email") %>'></asp:Label>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
I am Unable to bind the label Data to tab Container.. It is showing null
Try
Text = '<%# DataBinder.Eval(Container.DataItem, "Email" %>'
Inside form view I have drop down list on selected index change I have text box appearing.
Now I want to keep both these drop down and Text box inside Ajax update panel. Upon click button out side update panel I want to save these two fields as well.
Any help Much appreciated.
Here aspx code
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
<asp:DropDownList ID="ddlLName"
runat="server" ValidationGroup="VG1" SelectedValue='<%# Bind("LNAMEIFYES") %>' OnSelectedIndexChanged="ddlLName_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="">Please select...</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="2">No</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Panel ID="pnlLNAme" runat="server" Visible="false">
LName:
<asp:TextBox ID="LNameTextBox" runat="server" Text='<%# Bind("LName") %>' />
<br />
</asp:Panel>
Code Behind
protected void ddlLName_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlLName = (DropDownList)FormView1.FindControl("ddlLName");
if (ddlLName.SelectedValue == "1")
{
Panel pnlLNAme = (Panel)FormView1.FindControl("pnlLNAme");
pnlLNAme.Visible = true;
}
else
{
Panel pnlLNAme = (Panel)FormView1.FindControl("pnlLNAme");
pnlLNAme.Visible = false;
}
}
I solved the problem by using by using two update panals, using trigger in one of the update panal.
<EditItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
ID:
<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
<asp:DropDownList ID="ddlLName"
runat="server" ValidationGroup="VG1" SelectedValue='<%# Bind("LNAMEIFYES") %>' OnSelectedIndexChanged="ddlLName_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="">Please select...</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="2">No</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Panel ID="pnlLNAme" runat="server" Visible="false">
LName:
<asp:TextBox ID="LNameTextBox" runat="server" Text='<%# Bind("LName") %>' />
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
Salary:
<asp:TextBox ID="SalaryTextBox" runat="server" Text='<%# Bind("Salary") %>' />
<br />
IsActive:
<asp:CheckBox ID="IsActiveCheckBox" runat="server" Checked='<%# Bind("IsActive") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateButton" EventName="Click_Enent" />
</Triggers>
</asp:UpdatePanel>
</EditItemTemplate>
When I want to read e.CommandArgument then I get error saying "Input string was not in a correct format.". My markup portion is like bellow:
<asp:GridView ID="GridViewAllProducts" runat="server"
AutoGenerateColumns="False" GridLines="None"
AllowPaging="True" Width="100%"
EmptyDataText="هیچ محصولی پیدا نشد"
onrowcommand="GridViewAllProducts_RowCommand"
onrowdeleting="GridViewAllProducts_RowDeleting"
OnPageIndexChanging="GridViewAllProducts_PageIndexChanging">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div class='rowTableDiv rowAllNewsUC'>
<asp:HiddenField ID="hiddenId" runat="server" Value='<%# Bind("Id") %>' />
<img id="imgImage" src='<%# Bind("Image") %>' class="imgNewsAllNewsUC noBorder" alt="" runat="server" />
عنوان محصول: <asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label><br />
گروه: <asp:Label ID="lblCategory" runat="server" Text='<%# ProductC.GetProductCategoryName(Convert.ToInt32(Eval("CategoryId"))) %>'></asp:Label><br />
کد: <asp:Label ID="lblCode" runat="server" Text='<%# Bind("Code") %>'></asp:Label><br />
ابعاد: <asp:Label ID="lblDimention" runat="server" Text='<%# Bind("Dimention") %>'></asp:Label><br />
تعداد رنگ: <asp:Label ID="lblNumberOfColors" runat="server" Text='<%# Bind("NumberOfColors") %>'></asp:Label><br />
قیمت: <asp:Label ID="lblPrice" runat="server" Text='<%# nmsPublicClass.PublicClassC.ThousandSeparator(Convert.ToDecimal(Eval("Price"))) %>'></asp:Label>
<asp:LoginView ID="LoginView1" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="Administrator">
<ContentTemplate>
<div class='rowTableDiv rowInfoAllNewsUC'>
<asp:Panel ID="pnlEdit" CssClass='colTableDiv' runat="server">
<div class='colTableDiv colInfoAllNewsUC'>
<asp:LinkButton ID="lbEdit"
CommandArgument='<%# Bind("Id") %>'
PostBackUrl='<%# String.Format("~/Page/Admin/InsertProduct.aspx?Mode=Edit&Id={0}", Eval("Id"))%>'
Font-Underline="false"
CommandName="edit"
runat="server">
<img id='img2' class='noBorder imgEditAllNewsUC' src="../../image/note_edit.png" alt="ویرایش" />
ویراش</asp:LinkButton>
<asp:LinkButton ID="lbDelete" CommandArgument='<%# Bind("Id") %>' Font-Underline="false" CommandName="delete" runat="server">
<img id='img1' class='noBorder imgEditAllNewsUC' src="../../image/delete.png" alt="حذف" />
حذف</asp:LinkButton>
</div>
</asp:Panel>
</div>
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
<div class="divHidden">
<asp:Label ID="lblID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataRowStyle CssClass="lblError" />
<PagerStyle CssClass="pagerGridView" />
</asp:GridView>
My code behind is like bellow:
protected void GridViewAllProducts_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "delete")
{
int productId = Convert.ToInt32(e.CommandArgument);
string image = new ProductC().GetProductBy_Id(productId).Image;
Result r = new ProductC().DeleteBy_Id(productId);
if (r.IsSuccess)
{
File.Delete(Server.MapPath(image));
}
GridViewAllProducts.DataSource = new ProductC().GetAllProducts();
GridViewAllProducts.DataBind();
}
}
I get error "Input string was not in a correct format." at the following line:
int productId = Convert.ToInt32(e.CommandArgument);
What is the problem. Please help me. Thank you.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<asp:Repeater ID="rpChat" runat="server" OnItemDataBound="rpChat_ItemDataBound" OnItemCommand="rpChat_ItemCommand">
<ItemTemplate>
<div id="divChatWindow" title='<%# Eval("username") %>' runat="server" class="clChatWindow">
<div>
<asp:Label runat="server" Text='<%# Eval("username") %>' class="divHeader"></asp:Label>
<img src="../../Menu/close.jpg" onclick="HideDiv(this)" style="float: right; width: 20px;
height: 20px;" /></div>
<div class="chatText">
<asp:Repeater ID="rpChatMessages" runat="server">
<ItemTemplate>
<asp:Image ID="imageForFriend" runat="server" CssClass="clFriendsImage" ImageUrl='<%# "HttpImageHandler.jpg?username=" + DataBinder.Eval(Container.DataItem,"fromusername").ToString() %>' />
<asp:Label ID="chatMessage" runat="server" Text='<%# Eval("Message") %>'></asp:Label>
<br>
</ItemTemplate>
</asp:Repeater>
</div>
<asp:TextBox ID="txtChatMessage" runat="server" Width="115px"></asp:TextBox>
<asp:LinkButton ID="btnSendChat" runat="server" CommandName="Insert" CommandArgument='<%# Eval("username") %>'>Send</asp:LinkButton>
</div>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
I have edited the code... Now what should I do? I have the linkbutton inside contenttemplate. Still a postback is happening
Any postback coming from any control outside an UpdatePanel will trigger a full postback unless you add those events as triggers of your UpdatePanel
In your example,
<asp:LinkButton ID="btnSendChat" runat="server" CommandName="Insert" CommandArgument='<%# Eval("Username2") %>'>Send</asp:LinkButton>
It's outside of the UpdatePanel and since you do not have triggers in your panel that will always cause a full postback
Solutions:
Approach 1
Place the LinkButton inside the UpdatePanel.ContentTemplate
Approach 2
Add triggers to your UpdatePanel
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSendChat" EventName="Click" />
</Triggers>
I develop custom file uploader.
<asp:FileUpload runat="server" ID="fuUpload" />
<asp:UpdatePanel runat="server" >
<ContentTemplate>
<asp:Button ID="btnUpload" runat="server" Text="Upload" CausesValidation="false"
OnClick="btnUpload_Click" />
<div>
<asp:Label ID="lblError" runat="server" Visible="false" ForeColor="Red" /></div>
<asp:Repeater ID="rptAttachments" runat="server" OnItemCommand="Uploader_ItemCommand">
<ItemTemplate>
<div>
<a href='<%#GetUrl(....) %>'><%#Eval("Filename") %></a> <b>
<asp:LinkButton ID="lnkDelete" runat="server" Text="Удалить" CommandName="DeleteAttachment" CommandArgument='<%#Eval("FileName") %>' /></b>
</div>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUpload" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="rptAttachments" EventName="ItemCommand" />
</Triggers>
</asp:UpdatePanel>
protected void btnUpload_Click(object sender, EventArgs e)
{
//fuUpload.HasFile == false
if (fuUpload.HasFile && fuUpload.PostedFile != null
&& fuUpload.PostedFile.ContentLength > 0)
{
}
}
I wonder why fuUpload.HasFile always equls null.
Try these things.
Put <asp:FileUpload runat="server" ID="fuUpload" /> inside UpdatePanel
Set btnUpload trigger like this. <asp:PostBackTrigger ControlID="btnUpload" />