I am trying to get the text of a lable when someone clicks on a link button:
this is my code :
$(document).ready(function () {
$('[id*="lnkbtn_Remove"]').click(function (event) {
event.preventDefault();
var id = $("span[id*=lbl_Reference]").text();
alert(id);
});
});
But this gets me all the reference in the reapter as I am using "*". Is there anyway to get the actual reference on the row it has been clicked. Here is my html:
<asp:Repeater ID="rpt" runat="server" >
<ItemTemplate>
<div class="test">
<table>
<tr>
<td>
<div style="width: 230px;">
<asp:Label ID="lbl_Len" runat="server" CssClass="font_bold"></asp:Label>
<br />
<asp:Label ID="lbl_Reference" runat="server"></asp:Label>
</div>
</td>
<td align="left">
<div style="width: 80px;">
<asp:LinkButton ID="lnkbtn_Remove" runat="server" CssClass="rpt_item_Remove">Remove</asp:LinkButton>
</div>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
You can get it by something like this,
var lablelId = $(this).closest('.test').find('[id*=lbl_Reference']).attr('id');
var lablelText = $(this).closest('.test').find('[id*=lbl_Reference]').text();
If you want to find how many column set checked and if checked then want to find label value that nested inside repeater table row PFB :-
var chkValue = $("#TableID [id*=chkBoxId]");
for (var i = 0; i < chkValue.length; i++) {
if (chkValue[i].checked)
$('#TableID tr:eq(' + (i+1) + ') td:eq(0)').find('[id*=lblIds]').text() ;
Related
I have a Products page which displays a list of products. When i click Details button, i want to show product details in a bootstrap modal popup.
I want to get one of the product detail but this code gets all products details.
how can i fix this query:
.aspx code:
<asp:Repeater ID="rpProducts" runat="server">
<ItemTemplate>
<td> <div class="btn-ud" ><a href="<%#Eval("ProductID") %>" data-toggle="modal" data-target="#myModal2" class="btn btn-custom-3 btn-sm"/ >Details</a> </div> </td>
</ItemTemplate>
</asp:Repeater>
modal popup code:
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
<asp:Repeater ID="rpProductDetails" runat="server">
<ItemTemplate>
<tbody>
<td height="100px"> <%#Eval("ProductDetails")%> </td>
<td height="100px"> <%#Eval("ProductDetails")%> </td>
</tbody>
</ItemTemplate>
</asp:Repeater>
</div>
c# code:
DataTable dtProductsDetails = system.GetDataTable("Select ProductDetails,TechDetails,Standards, ApplicationArea from TBLPRODUCTS where ProductID = ProductID");
if (dtProductsDetails.Rows.Count > 0)
{
rpProductDetails.DataSource = dtProductsDetails;
rpProductDetails.DataBind();
}
<script type="text/javascript">
function openModal() {
$('#myModal').modal('show');
}
</script>
In your c# code add an event for linkbutton like
protected void lbEdit_Click(object sender, EventArgs e) {
ScriptManager.RegisterStartupScript(this,this.GetType(),"Pop","openModal();", true);
}
You have to use jQuery for this:
$("a").click(function(){
$("#myModal2").modal("show");
});
I'm working on a project and ran into a problem.
For some reason, I can't assign data source to the repeater. I'm using usercontrol
SlideshowDemo.ascx
<asp:Repeater ID="Slideshow" runat="server">
<HeaderTemplate>
<div style="margin:0 auto; width:960px;">
<div class="slideshowInsideContainer">
<div class="slideShowText">
<div style="padding:10px;" class="SlideShowContent">
<%= firstText %>
</div>
</div>
<img id="SlideShowImage" style="position:absolute; z-index:1; top:0;" src="<%= firstImage %>" />
<img id="SlideShowImageBG" style="position:absolute; z-index:0; top:0;" src="<%= firstImage %>" />
<img id="previousBttn" style="position:absolute; z-index:2; top:200px; cursor:pointer; left:0;" src="/images/SlideShow/leftButton.png" />
<img id="nextBttn" style="position:absolute; z-index:2; top:200px; cursor:pointer; right:0;" src="/images/SlideShow/rightButton.png" />
<div class="slideshowItems">
<ul>
</HeaderTemplate>
<ItemTemplate>
<li class='<%# Container.ItemIndex == 0 ? "selected" : "" %>' id="<%# Container.ItemIndex %>">
<div class="slideshowtext">
<%# Eval("text") %>
</div>
<img style="position:absolute; z-index:1; top:0;" src=' <%# Eval("image") %>' />
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</div>
</div>
</div>
</FooterTemplate>
</asp:Repeater>
SlideshowDemo.ascx.cs
public void GetSlideshowData()
{
int ID = Convert.ToInt32(slideShowID);
Node parent = new Node(ID);
ArrayList repeaterData = new ArrayList();
Nodes children = parent.Children;
for (int i = 0; i < children.Count; i++)
{
string image = children[i].GetProperty("image").Value.ToString();
string text = children[i].GetProperty("slideshowText").Value.ToString();
if (i == 0)
{
firstImage = image;
firstText = text;
}
repeaterData.Add(new SlideShowItem(image, text));
}
Slideshow.DataSource = repeaterData; //Error: Can't recognize 'Slideshow'
Slideshow.DataBind();
}
The problem is that the SlideshowDemo.ascx.cs doesn't recognize Slideshow
I get error
The name 'Slideshow' does not exist in the current context
I also get Warning
Source file
'obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs'
specified multiple times
I would appreciate any help
I have a dropdown for prefix, the value for dropdown from a table. The values are listed below
--Select--
Dr.
Mr.
Mrs.
Ms.
Miss.
Other..
When the user select the value -1,then a text box should appear,otherwise hide that.
<tr>
<td class="leftTD">
<span class="textfield">Prefix</span> <span class="required">*</span>
</td>
<td class="rightTD">
<div class="highlight">
<asp:DropDownList ID="ddlPrefix" runat="server" CssClass="dropdown" TabIndex="12"
onchange="chekRequiredField(this); javascript:hideRow(this.id,'trOther');">
</asp:DropDownList>
</div>
</td>
</tr>
<tr id="trOther" runat="server" style="display: none;">
<td class="leftTD">
<span class="textfield">Other Title</span>
</td>
<td class="rightTD">
<asp:TextBox ID="txtOther" runat="server" TabIndex="12" MaxLength="50" CssClass="textbox"></asp:TextBox>
</td>
</tr>
Code Behind Code, The method for getting dropdown value given below:
private void PopulateDetails(int registrationid)
{
ddlTitle.SelectedValue = BLUtil.ToString(objMOAdministrativeApproval.ObjAdministrativeApproval.Tittle);
if (ddlPrefix.SelectedValue == "-1")
{
trOther.Style.Add("display", "");
txtOther.Text = BLUtil.HtmlDecode(objMOAdministrativeApproval.ObjAdministrativeApproval.OtherTitle);
}
else
{
trOther.Style.Add("display", "none");
}
}
Sometimes, I will get an error in PopulateDetails method. But sometimes its ok.
Method Name : PopulateDetails(int registrationid)
Message : 'ddlPrefix' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
How can I handle this exception?
After sucessfull sending mail with asp.net I want to execute jQuery script
.NET Code:
void btnSubmit_Click(Object sender, EventArgs e) {
MailMessage objEmail = new MailMessage();
objEmail.To = "mymail#com";
objEmail.From = txtFrom.Text;
objEmail.Cc = txtCc.Text;
objEmail.Subject = "Contact";
objEmail.Body = "note: " + txtComments.Text + " <br> " + "name:" + txtName.Text;
objEmail.Priority = MailPriority.High;
objEmail.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer = "localhost";
try{
SmtpMail.Send(objEmail);
Response.Write("Email send");
}
catch (Exception exc){
Response.Write("");
}
}
jQuery:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function() {
var par = $('.x');
$(par).hide();
$("button").click(function(){
$(".x").toggle();
});
});
</script>
Both scripts works perfecty, but I have no idea how to combine them in order to close contact form after successful sending mail.
Here is whole contact form:
<div align="center"><button class="button">Napisz do nas!</button></div>
<div class="x">
<form runat="server">
<div align="center">
<table border="0" width="350">
<tr>
<td valign="top"><font face="Verdana" size="2">Imię i Nazwisko:</font></td>
<td height="20"> <asp:TextBox runat="server" Height="21px" Width="215px" ID="txtName"></asp:TextBox>
<br>
<asp:RequiredFieldValidator ID = "req1" ControlToValidate = "txtFrom" Runat = "server" ErrorMessage = "Proszę podać Imię i Nazwisko "></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td valign="top"><font face="Verdana" size="2">E-mail:</font></td>
<td height="24"> <asp:TextBox runat="server" Height="22px" Width="213px" ID="txtFrom"></asp:TextBox>
<br>
<asp:RegularExpressionValidator ID = "reg1" ControlToValidate = "txtFrom" Runat = "server" ErrorMessage = "Invalid Email" ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> <asp:RequiredFieldValidator ID = "req3" ControlToValidate = "txtFrom" Runat = "server" ErrorMessage = "Nieprawidłowy Email" ></asp:RequiredFieldValidator></td>
</tr>
<!--<tr>
<td valign="top"><font face="Verdana" size="2">To</font></td>
<td height="24" valign="top">
<asp:TextBox runat="server" Height="22px" Width="212px" ID="txtTo"></asp:TextBox>
<br>
<asp:RegularExpressionValidator ID = "reg2" ControlToValidate = "txtTo" Runat = "server" ErrorMessage = "Invalid Email" ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID = "req4" ControlToValidate = "txtTo" Runat = "server" ErrorMessage = "Please enter recipients E-mail" ></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td valign="top"><font face="Verdana" size="2">Cc</font></td>
<td height="24" valign="top">
<asp:TextBox runat="server" Height="22px" Width="210px" ID="txtCc"></asp:TextBox>
<br>
<asp:RegularExpressionValidator ID = "reg3" ControlToValidate = "txtCc" Runat = "server" ErrorMessage = "Invalid Email" ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>-->
<tr>
<td valign="top"><font face="Verdana" size="2">Wiadomość:</font></td>
<td height="80"> <asp:TextBox runat="server" Height="80px" TextMode="Multiline" rows="4" Width="258px" ID="txtComments"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" valign="top" height="10" align="center">
<asp:Button Runat = server ID = btnSubmit OnClick = btnSubmit_Click Text = "Wyślij"></asp:Button>
<input type = "reset" runat = "server" value = "Wyczyść"></td>
</tr>
</table>
</div>
</form>
</div>
Most of the time when I need to do this, I place the javascript code in a asp.net placeholder control, which I set to be invisible at page load, and change it to visible when I need to execute the javascript.
This would also allow you to handle the try, catch and finally statements by doing it with 3 different placeholders...
What you have to remember is that the .NET code runs on the server and the jQuery code runs in the browser. There is no direct way to "call" JavaScript from .NET.
You can use the ClientScript property of the page object to inject the JavaScript into your page so that when the new page gets rendered into the browser it will contain the script and execute it.
http://msdn.microsoft.com/en-us/library/btf44dc9(v=vs.110).aspx
<div id="x" runat="server">
<!-- your html -->
</div>
In case of successful send of email of the btnSubmit_Click:
x.Visible = false;
Why do popup does not work sometimes. There is no condition for popup. Whenever a button is clicked, it has to pop. Where do you guys think the problem might be??
Thanks,
<table id="pnlPopupAdditional" runat="server" style="display:none">
<tr>
<td>
<asp:Panel runat="server" CssClass="modalPopup">
<table width="350" height="80" class="warningPopup">
<tr>
<td>
<!-- <img src="images/warning_blue.gif" alt="Warning" /> -->
</td>
<td colspan="2" align="left" style="padding-left: 75px; padding-top: 10px;">
<asp:Literal ID="ltMessage" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td align="center" colspan="4">
<input id="btnYesAdditional" type="button" value="YES" class="popupButton" />
<input id="btnNoAdditional" type="button" value="NO" class="popupButton" />
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
<asp:Button ID="btn" runat="server" Visible="false" />
private void SetAdditionalLocationMessage()
{
_AccountSummary accountSummary = new _AccountSummary();
accountSummary = new Merchant2().GetAccountSummary(MerchantID);
if (accountSummary != null)
{
if (accountSummary.PackageID != (int)CommonHelper.Package.Free )
btnAdd.Visible = true;
else
btnAdd.Visible = false;
}
if (new Merchant2().IsLocationCountExceed(MerchantID))
{
string locationFee = new Merchant2().GetAdditionalLocationFee(accountSummary.PackageID).ToString();
ltMessage.Text = String.Format(ApplicationData.MSG_ADDITIONAL_LOCATION_CHARGE, locationFee);
ModalPopupExtender1.TargetControlID = "btnAdd";
ConfirmButtonExtender1.TargetControlID = "btnAdd";
}
else
{
ModalPopupExtender1.TargetControlID = "btn";
ConfirmButtonExtender1.TargetControlID = "btn";
}
//Controls_UC
protected void btnAdd_Click(object sender, ImageClickEventArgs e)
{
MerchantID = CommonHelper.GetLoggedInMerchant();
string QueryString = ApplicationData.URL_MERCHANT_COMPANY_PAYMENT + "?MerchantProfilePages";
Response.Redirect(QueryString);
It may be a result of JavaScript referenced DOM elements being disposed of during an AJAX request.
This is assuming you are acquiring a JavaScript reference of the DOM element referenced via pnlPopupAdditional.ClientID, so that you may modify the display:none; style declaration.