How to get element ID's inside repeater control - c#

I am creating a social network site, I cant seem to get the "LinkEmail" in the code behind, I need this to function as I then use it to post to the database.
The LinkEmail is being dynamically generated in the first repeater, I need a way to grab that value.
at the moment I am getting this error in the browser:
Compiler Error Message: CS0103: The name 'LinkEmail' does not exist in the current context
this is aspx code
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<div style="border-top: thin none #91ADDD; border-bottom: thin none #91ADDD; padding: 10px; width: 548px; margin-top: 10px; right: 10px; left: 10px; border-left-width: thin; margin-left: 15px; background-color: #F6F6F6; border-left-color: #91ADDD; border-right-color: #91ADDD;">
<br />
<div style="width: 58px; height: 40px">
<asp:Image ID="Image2" runat="server" Height="59px" ImageAlign="Top" ImageUrl="~/Profile/Image/Default.png" Width="55px" />
</div>
<div style="width: 307px; margin-left: 65px; margin-top: -60px">
<asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Names="Arial" ForeColor="#3b5998"><%#Eval("YourName") %> </asp:Label>
</div>
<div id="status" style=" width: 461px; margin-left: 78px; margin-top: 11px;"> <asp:Label ID="Label7" runat="server" Font-Italic="False" ForeColor="Black" Font-Size="Medium"><%#Eval("Birthday") %> </asp:Label>
<asp:LinkButton ID="LinkEmail" runat="server" OnClick="lbl_Click"><%#Eval("Email") %></asp:LinkButton>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</div>
</ItemTemplate>
Could you tell me How to get LinkButton ID to my code behind file?

You can find it in ItemCommand event like this:-
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
LinkButton LinkEmail= e.Item.FindControl("LinkEmail") as LinkButton ;
}
You need to associate this event handler with your control like this:-
<asp:Repeater runat="server" ID="Repeater1" OnItemCommand="Repeater1_ItemCommand">

foreach(RepeaterItem item in Repeater1.Items)
{
LinkButton LinkEmail=(LinkButton)item.FindControl("LinkEmail");
//Do here what ever you want
}
using Sender
You get the RepeaterItem by casting the Link button's NamingContainer. Then you can use FindControl to get the reference to your Other Controls.
protected void lbl_Click(object sender,EventArgs e)
{
LinkButton LinkEmail=(LinkButton) sender;
var RepeaterRow=(RepeaterItem)LinkEmail.NamingContainer;
//find your other control like this
Label Label6=(Label) RepeaterRow.FindControl("controlname")
//Do here what ever you want
}
Or
You can use ItemCommand as Suggested by Rahul singh

Related

How to diplay a popup window when changing the selected value in a dropdown list?

I want to display a popup window when I select a specific value from drop-down list. But I don't have any idea to do it as I want. I little example would be enough for this. For the pop up I expect to use panel.
It's pretty simple.Use SelectedIndexChanged event of dropdownlist
.aspx
<asp:ModalPopupExtender ID="ModalPopupExtender2" runat="server" Enabled="false" PopupControlID="PanelMonthly" TargetControlID="ddlfeegroup">
.cs
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
ModalPopupExtender2.Enabled = true;
ModalPopupExtender2.Show();//popup show
}
on close button event again make ModalPopupExtender2.Enabled = false; or onclienclick of close button disable it
You can find more information here
Hope this will work
<asp:HiddenField ID="hidForModel" runat="server" />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1"></asp:DropDownList>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<!-- ModalPopupExtender -->
<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="hidForModel"
CancelControlID="btnClose" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" Style="display: none">
<asp:Button ID="btnClose" runat="server" Text="Close" />
</asp:Panel>
<!-- ModalPopupExtender -->
.cs code
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
mp1.Show();
}
css
<style type="text/css">
.modalBackground {
background-color: Black;
filter: alpha(opacity=90);
opacity: 0.8;
}
.modalPopup {
background-color: #FFFFFF;
border-width: 3px;
border-style: solid;
border-color: black;
padding-top: 10px;
padding-left: 10px;
width: 300px;
height: 140px;
}
</style>

Refresh repeater control within few seconds continuously

hi i am doing a social network service on asp.net c#.I want to refresh the messages within 1 second without loading whole page. I am display messages using repeater control.
I want to refresh this repeater control continuously after 1 second, but whole page should not be reloaded.
repeater control code
setInterval(function () { $(".refresh").load(location.href + " .refresh"); }, 1000);
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<div style="border-top: thin none #BBCEB3; border-bottom: thin none #BBCEB3; padding: 10px; width: 548px; margin-top: 10px; right: 10px; left: 10px; border-left-width: thin; margin-left: 15px; background-color: #e9eaee; border-left-color: #BBCEB3; border-right-color: #BBCEB3;">
<br />
<div style="width: 58px; height: 40px">
<asp:Image ID="Image2" runat="server" Height="59px" ImageAlign="Top" ImageUrl="~/Profile/Image/Default.png" Width="55px" />
</div>
<div style="width: 307px; margin-left: 65px; margin-top: -60px">
<asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Names="Arial" ForeColor="#000066"><%#Eval("SenderID") %> </asp:Label>
</div>
<div id="status" style=" width: 461px; margin-left: 78px; margin-top: 11px;"> <asp:Label ID="Label7" runat="server" Font-Italic="False" ForeColor="Black" Font-Size="Medium"><%#Eval("Messages") %> </asp:Label>
</div>
<div style="margin-left: 350px">
<asp:Label ID="Label11" runat="server" Text="Posted on: " Font-Size="Small"><%#Eval("Time") %> </asp:Label>
</div>
</div>
</ItemTemplate>
textbox code
<asp:TextBox ID="Message" runat="server" OnTextChanged="TextBox3_TextChanged" style="margin-left: 12px; text-align: left;" TextMode="MultiLine" Width="564px" Height="100px"></asp:TextBox>
Hope this helps:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Trans.aspx.cs" Inherits="WebClient.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script>
$(document).ready(
function() {
setInterval(function () { $('#Repeater1').load(location.href + " #Repeater1"); }, 1000);
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<div style="border-top: thin none #BBCEB3; border-bottom: thin none #BBCEB3; padding: 10px; width: 548px; margin-top: 10px; right: 10px; left: 10px; border-left-width: thin; margin-left: 15px; background-color: #e9eaee; border-left-color: #BBCEB3; border-right-color: #BBCEB3;">
<br />
<div style="width: 58px; height: 40px">
<asp:Image ID="Image2" runat="server" Height="59px" ImageAlign="Top" ImageUrl="~/Profile/Image/Default.png" Width="55px" />
</div>
<div style="width: 307px; margin-left: 65px; margin-top: -60px">
<asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Names="Arial" ForeColor="#000066"><%#Eval("SenderID") %> </asp:Label>
</div>
<div id="status" style=" width: 461px; margin-left: 78px; margin-top: 11px;"> <asp:Label ID="Label7" runat="server" Font-Italic="False" ForeColor="Black" Font-Size="Medium"><%#Eval("Messages") %> </asp:Label>
</div>
<div style="margin-left: 350px">
<asp:Label ID="Label11" runat="server" Text="Posted on: " Font-Size="Small"><%#Eval("Time") %> </asp:Label>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</asp:Content>

Repeater content not visible after UpdatePanel PreRender

I have a repeater which i am trying to load after the page has loaded and have stumbled across the PreRender event. I have everything set up but the content of the repeater is not showing - the weird thing is that when i inspect the html, the code is there, just not displaying in the browser.
<asp:updatepanel id="panel1" runat="server" updatemode="Conditional" onprerender="upUpdatePanel_PreRender">
<contenttemplate>
<asp:repeater runat="server" id="mainContentRptr" onitemdatabound="bindDepts">
<headertemplate>
<div id="products-tabs-content" class="row tab-content">
</headertemplate>
<itemtemplate>
<div class="tab-pane" id='<%# eval("dept_id") %>
'> <asp:repeater runat="server" id="prodRepeater" onitemcommand="itemToCart">
<headertemplate>
.... </headertemplate>
<itemtemplate>
.... <asp:repeater runat="server" id="condRptr">
<headertemplate>
.... </headertemplate>
<itemtemplate>
.... </itemtemplate>
<footertemplate></footertemplate>
</asp:repeater>
</itemtemplate>
<footertemplate>
</div>
</footertemplate>
</asp:repeater>
</div>
<!-- End .tab-pane -->
</itemtemplate>
<footertemplate>
</footertemplate>
</asp:repeater>
</contenttemplate>
</asp:updatepanel>
As you can see a few nested repeaters... i also have my UpdateProgress control
<asp:UpdateProgress id="updateProgress" runat="server" AssociatedUpdatePanelID="panel1">
<ProgressTemplate>
<div style="position: relative; text-align: center; height: 100%; width: 100%; background-color: white; opacity: 0.7;margin:0 auto">
<asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="images/loader.GIF" AlternateText="Loading ..." ToolTip="Loading ..." style="padding: 10px; position: relative; top: 45%;margin: 0 auto" />
<br/>
<span style="font-size: 16pt;font-weight: bold">Bulding your menu</span>
<br/>
<span>Please wait</span>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
and then the following to trigger the delayed load
<script language="javascript" type="text/javascript">
function pageLoad(sender, e) {
if (!e.get_isPartialLoad()) {
__doPostBack('<%= panel1.ClientID %>', 'aaaa');
}
}
</script>
and server side...
protected void upUpdatePanel_PreRender(object sender, EventArgs e)
{
if (Request["__EVENTTARGET"] == panel1.ClientID &&
Request.Form["__EVENTARGUMENT"] == "aaaa")
{
populateRepeaters(); //This has databind for each repeater
}
}
This works without the prerender but loading speeding will vary depending on data etc so i wanted to have it load after the page loaded.
Any help would be appreciated guys! :)
a repeater was sitting out of the updatepanel that controlled the visibility of everything above. it was populated in the prerender event but did not display. Ive moved it inside the panel and everyhting is now working

Pass an ID to OnClick event with Repeater control?

Here is my screen:
Here is my code for the ItemTemplate in the Repeater:
<ItemTemplate>
<div style="float: left; overflow: hidden; display: inline-block; border-style: solid; margin: 5px; background-color: Silver">
<div style="text-align:center">
<asp:Label ID="lblImage" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "image") %>'></asp:Label>
</div>
<asp:Image runat="server" ID="image1" Width="250px" Height="250px" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "url") %>' />
<div style="text-align: center;">
<asp:Button runat="server" ID="btnNew" Text="New" />
<asp:Button runat="server" ID="btnOriginal" Text="Original" />
</div>
</div>
The Repeater uses a dataset in my program to populate the ItemTemplate's label and image controls. There's another field in my dataset called graphicID. I'd like to, somehow, pass the value in that field to the 'Original' button, so that if a user presses that button, that particular graphicID is passed into the click event. Does this make sense?
For instance, the second image is Captain Harlock. The graphicID for this image is 93. If the user presses the Original button under Captain Harlock, I want to pass 93 to the onClick event. I'm not sure how to do this, though. If someone could point me in the right direction, I'd greatly appreciate it!
<div style="text-align: center;">
<asp:Button runat="server" ID="btnNew" Text="New" />
<asp:Button runat="server" CommandName="cmd_original" CommandArgument="name of field which you want to access" ID="btnOriginal" Text="Original" />
</div>
EDIT
In repeater control
you have to add an event as below:
onitemcommand="Repeater1_ItemCommand"
In code behind
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "cmd_original")
{
Int32 id = Convert.ToInt32(e.CommandArgument);
}
}

Lock Screen on my email sending page asp.net

i have a page wherein i need to lock the screen when user clicks on the send email button, but everything is happening except i am unable to see my lock screen page. i have used the update progress for this purpose.. m posting part of the code here
.aspx part
<asp:UpdatePanel ID="SendMailUpdatePanel" runat="server">
<ContentTemplate>
<div style="float: right;">
<asp:Button ID="btnSend" runat="server" Text="Send" ToolTip="Send "
Visible="false" Font-Bold="True" OnClick="btnSendResume_Click" />
<asp:Button ID="btnDown" runat="server" Text="Download IDs" ToolTip="follow-up"
Visible="false" Font-Bold="True" OnClick="btnDownloadEmailIDs_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
<table>
<td style="width: auto; vertical-align: top;">
<asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="SendMailUpdatePanel">
<ProgressTemplate>
<div id="blur" style="width: 100%; background-color: black; moz-opacity: 0.5; khtml-opacity: .5;
opacity: .5; filter: alpha(opacity=50); z-index: 120; height: 100%; position: absolute;
top: 0; left: 0;">
<div id="progress" style="z-index: 200; background-color: White; position: absolute; top: 0pt;
left: 0pt; border: solid 1px black; padding: 5px 5px 5px 5px; text-align: center;">
<b>Mail in progress.Please Wait...</b>
<br />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</table>
.cs part
protected void btnSendResume_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(2000);
}
rest of the part i have not mentioned here...any help
Your HTML Table is incorrectly formed. You have no <tr> elements, but the real problem probably lies with your style attributes, please see my updated code below.
You can find a good example of how to accomplish what you are trying to do here: http://blogs.visoftinc.com/2008/03/13/Modal-UpdateProgress-for-UpdatePanel-Revisited/
Try adjusting your code to the following:
<asp:UpdatePanel ID="SendMailUpdatePanel" runat="server">
<ContentTemplate>
<div style="float: right;">
<asp:Button ID="btnSend" runat="server" Text="Send" ToolTip="Send "
Visible="false" Font-Bold="True" OnClick="btnSendResume_Click" />
<asp:Button ID="btnDown" runat="server" Text="Download IDs" ToolTip="follow-up"
Visible="false" Font-Bold="True" OnClick="btnDownloadEmailIDs_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="SendMailUpdatePanel">
<ProgressTemplate>
<div id="blur" style="position:fixed; top:0px; bottom:0px; left:0px; right:0px; overflow:hidden; padding:0; margin:0; background-color:black; filter:alpha(opacity=50); opacity:0.5; z-index:1000;" />
<div id="progress" style="position:fixed; top:30%; left:43%; width:14%; z-index:1001; background-color:white; border:solid 1px black; padding:5px; text-align:center;">
<b>Mail in progress.Please Wait...</b>
<br />
<br />
</div>
</ProgressTemplate>
</asp:UpdateProgress>

Categories