I'm new here, I'm stuck in problem in which i have to loop my button so that i will be able to put it on my looping div. How will I do that? This is what I got so far:
//my loop
for (i = 0; i < MPreply.recommendation.Length; i++) {
html += "<div class='rec'> ";
html += "</br> <div id = 'from1' value = > Depart From:" + " ";
html += emz + " " + "(" + + ")" + "</div>";
html += "<div id = 'date1' > Schedule:" + " " + flytDate;
html += " , " + convertedString;
html += "</div>" + "<div id = 'to1' >To:" + " " + emz2 + " " + "(" + "" + ")";
html += "</div> </br> </br> </br> ";
html += "<div id = 'RecNo'>" + " " + (i + 1) + " )" + " </br> </br> </div> ";
html += "<div id = 'fare1'> $" + em + " </div> ";
html += " </div> <br/> <br/>";
div_rec.InnerHtml = html;
}
html:
<div id = 'modal' runat="server" >
<div id="dialog" runat="server">
</div>
<input id="_menuitem" type="button" value="Click" runat="server" />
</div>
Thanks in advance.
You have at least a few problems:
"<div id = 'fare1'>
and similar sections will generate multiple elements with the same id.
div_rec.InnerHtml = html;
Should be moved outside of your loop so that div_rec is only updated once, when everything is done.
emz + " " + "(" + + ")" + "</div>";
Should (probably) be changed to
emz + " " + "(" + your_variable_here + ")" + "</div>";
In order to (I think) add the creation of a button in your loop, you'll have to piece it together as a string just like your other elements. To get a function handler wired up you'll have to either:
a) Build a dom level-0 handler as a string, or
b) Wait until your html is updated, then query out the newly added buttons and add event handlers in code (using either btn.onclick = function(... or dom level-2 handlers (addEventListener or attachEvent)
The Problem i see here is with the ID field.
You have mentioned same ID name for all the Div's you are generating.
Like,
<div id = 'from1'>
<div id = 'to1'>
ID is a unique identifier to an element. It must always be unique.
You can Use Class instead.
Like,
<div class = 'from1'>
<div class = 'to1'>
Related
<div id="ctl00_cphRoblox_rbxGroupFundsPane_GroupFunds" class="StandardBox" style="padding-right:0">
<b>Funds:</b>
<span class="robux" style="margin-left:5px">128</span>
</div>
Ok so I want to get the 128 but sometimes it gives me "18"
and I have no idea
I tried:
dcWeb.SendMessage(s + " = Pending and Robux: " + driver.FindElement(By.ClassName("robux")).GetAttribute("innerHTML"));
and
dcWeb.SendMessage(s + " = Pending and Robux: " + driver.FindElement(By.ClassName("robux")).GetAttribute("textContent"));
To to get the text 128 you can use the following line of code :
dcWeb.SendMessage(s + " = Pending and Robux: " + driver.FindElement(By.XPath("//div[#class='StandardBox' and contains(#id,'_cphRoblox_rbxGroupFundsPane_GroupFunds')]//span[#class='robux']")).GetAttribute("innerHTML"));
I want the checkbox wrapped in a label so that if they click the Label it will check the CheckBox. I also need the descArea to diplay once the hover over the Label. These must also be dynamic and created in the code behind. I have 2 ways so far, both with their own issue...
This option doesn't allow the JS functions to be called for the descArea to slide down
caPanel.Controls.Add(new LiteralControl(
"<div class='col-md-6'>"+
"<div id='AButton" + t.Rows[i]["ID"].ToString() + "' class='caLabel' onmouseenter='slideDescriptionDown(this.id);' onmouseleave='slideDescriptionDown(this.id);' >" +
"<label>"));
CheckBox aCheckBox = new CheckBox();
aCheckBox.ID = "checkbox" + t.Rows[i]["ID"].ToString();
caPanel.Controls.Add(aCheckBox);
ca.Controls.Add(new LiteralControl(" " + t.Rows[i]["NAME"].ToString() +
"</label>"+
"</div>"+
"<div class='alert alert-info aDescription' id='descArea" + t.Rows[i]["ID"].ToString() + "'>" +
"<span id='desc" + t.Rows[i]["CA_ID"].ToString() + "'>" + t.Rows[i]["Description"].ToString() + "</span>" +
"</div>"+
"</div>"));
This one doesn't allow the CheckBox to be checked when clicking the Label. I inspected the code and the Label is showing up as a span
caPanel.Controls.Add(new LiteralControl("<div class='row caSectionRow'>" +
"<div class='col-md-6'>"));
Label aName = new Label();
aName.ID = "AButton" + t.Rows[i]["ID"].ToString();
aName.Attributes.Add("class", "caLabel");
aName.Attributes.Add("onmouseenter", "slideDescriptionDown(this.id);");
aName.Attributes.Add("onmouseleave", "slideDescriptionDown(this.id);");
aName.Text = " " + t.Rows[i]["NAME"].ToString();
CheckBox aCheckBox = new CheckBox();
aCheckBox.ID = "checkbox" + t.Rows[i]["ID"].ToString();
caPanel.Controls.Add(aCheckBox);
caPanel.Controls.Add(aName);
caPanel.Controls.Add(new LiteralControl(
"<div class='alert alert-info aDescription' id='descArea" + t.Rows[i]["ID"].ToString() + "'>" +
"<span id='desc" + t.Rows[i]["ID"].ToString() + "'>" + t.Rows[i]["Description"].ToString() + "</span>" +
"</div>" +
"</div>"));
I found the error lied within the JS function itself when trying to display the descArea for the first option I proposed. I didn't have the ID for the descArea correct. It was prepended with the MainContent_aContent_ to fulfill UniqueID property all controls must have in ASP.NET.
When is the ctl00 prefix added?
https://msdn.microsoft.com/en-us/library/1d04y8ss(v=vs.100).ASPX
i have a class named "row" that has 3 item {property,instance,degree}.
now i want to show my items or rows to user and if he changed the third part of class i edit it. this is my code of generating rows dynamically, numberOfInstance is number of rows.
<div id="hidden" class="hiddendiv">
<%
string matn = "";
for (int i = 0; i < numberOfInstance ; i++)
{
row r= new row();
r = a[i];
matn+= " <div class='CMSdiv'>";
matn += "<input id='Text"+i+"' class='labelhid' type='text'"+"value = '"+r.Property+ "'/>";
matn += "<input id='Text2" + i + "' class='labelhid' type='text'" + "value = '" + r.instance+ "'/>";
matn += " <select id='Select" +i+ "'class='drophid' runat='server'>";
matn += " <option value= '"+ "خیلی زیاد"+"'>خیلی زیاد" + " <option value= '"+"زیاد'"+">زیاد";
matn += " <option value='"+"متوسط'"+">متوسط";
matn += " <option value='" + "کم'" + ">کم";
matn += "</select>";
matn += "</div>";
Response.Write(matn);
matn = "";
}
%>
</div>
now if user clicked on select and choose one option, i get it's value and pour to r.degree in code behind. but whatever i did i couldn't find it in code behind and was null. these are my attempts:
var val = Request["Select" + i];
string selection = Request.Form["Select" + i];
hd = (HiddenField)Page.FindControl("Select" + i);
hd = (HiddenField)Control.FindControl("Select" + i);
You can't generate server side controls by Response.Write (More info here). So html elements that you are writing to output are client side controls not server side and cannot be found using the Page.FindControl method.
Consider using one of the server side controls like Repeater instead.
It's print double, I can't see any error of my code, I use match collection in regular expression, if match collection found 2 (youtube link). the function print 4 images. by the way the function get the youtube thumnails.
Plaintext:
string Plainttext = "This selection is automatically generated based on videos that were popular <br/>" +
" in the past few weeks. <br/>" +
" ------------------------------------------------------------------- \n" +
" 'Anniversary Prank Backfires!! \n" +
" http://www.youtube.com/watch?v=R7AXBOT8KzU&feature=em-hot \n" +
" by RomanAtwood " +
" 23,268,129 views " +
" ------------------------------------------------------------------- \n" +
" We Are The World for Philippines [TYPHOON HAIYAN] \n" +
" http://www.youtube.com/watch?v=1bI8pGLBagY&feature=em-hot \n" +
" by Kevin Ayson " +
" 3,607,584 views <br/>" +
" ------------------------------------------------------------------- <br/>" +
" end of text ";
Button:
protected void Button1_Click(object sender, EventArgs e)
{
Literal1.Text = GetYoutubeThumbnails(Plainttext);
}
Function:
string geturl;// static string id ;
protected string GetYoutubeThumbnails(string plaintext)
{
var youtuberegex = new Regex("youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
StringBuilder sb = new StringBuilder();
MatchCollection matches = youtuberegex.Matches(plaintext);
ArrayList arrayURL = new ArrayList(matches);
// foreach (Match match in matches)
for (int i = 0; i <= arrayURL.Count-1 ; i++ )
{
geturl = arrayURL[i].ToString();
string id = string.Empty;
Match youtubeMatch = youtuberegex.Match(geturl);
id = youtubeMatch.Groups[1].Value;
// if(match.Success)
// {
sb.Append(string.Format(#"<table runat ='server'><tr> <td id = 'tduserPicture'
rowspan='1' style='text-align:left' runat='server'>
<img ID='Imagess2' runat='server' src='{0}' Height='80px' Width='100px' /alt='image'>
<br/> {1} </td> </tr></table>", "http://img.youtube.com/vi/" + id + "/0.jpg", "www." + geturl));
// }
}
plaintext = youtuberegex.Replace(plaintext, sb.ToString());
return plaintext;
}
Output:
Thanks
The problem is your modifying the text inside your loop, a separate output should be created rather than an in-place replace.
Don't even bother doing it like that, use a Regex.Replace callback function.
Knocked this together as a super quick sample
using System.IO;
using System;
using System.Collections;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string Plainttext = "This selection is automatically generated based on videos that were popular <br/>" +
" in the past few weeks. <br/>" +
" ------------------------------------------------------------------- \n" +
" 'Anniversary Prank Backfires!! \n" +
" http://www.youtube.com/watch?v=R7AXBOT8KzU&feature=em-hot \n" +
" by RomanAtwood " +
" 23,268,129 views " +
" ------------------------------------------------------------------- \n" +
" We Are The World for Philippines [TYPHOON HAIYAN] \n" +
" http://www.youtube.com/watch?v=1bI8pGLBagY&feature=em-hot \n" +
" by Kevin Ayson " +
" 3,607,584 views <br/>" +
" ------------------------------------------------------------------- <br/>" +
" end of text ";
MatchEvaluator evaluator = new MatchEvaluator(MatchFilter);
Console.WriteLine(Regex.Replace(Plainttext,
"youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)", evaluator,
RegexOptions.IgnorePatternWhitespace));
}
static string MatchFilter(Match match) {
var id = match.Groups[1].Value;
var geturl = match.ToString();
return string.Format(#"<table runat ='server'><tr> <td id = 'tduserPicture'
rowspan='1' style='text-align:left' runat='server'>
<img ID='Imagess2' runat='server' src='{0}' Height='80px' Width='100px' /alt='image'>
<br/> {1} </td> </tr></table>", "http://img.youtube.com/vi/" + id + "/0.jpg", "www." + geturl);
}
}
This outputs the following:
This selection is automatically generated based on videos that were popular <br/> in the past few weeks. <br/> -------------------------------------------------------------------
'Anniversary Prank Backfires!!
http://www.<table runat ='server'><tr> <td id = 'tduserPicture'
rowspan='1' style='text-align:left' runat='server'>
<img ID='Imagess2' runat='server' src='http://img.youtube.com/vi/R7AXBOT8KzU/0.jpg' Height='80px' Width='100px' /alt='image'>
<br/> www.youtube.com/watch?v=R7AXBOT8KzU </td> </tr></table>&feature=em-hot
by RomanAtwood 23,268,129 views -------------------------------------------------------------------
We Are The World for Philippines [TYPHOON HAIYAN]
http://www.<table runat ='server'><tr> <td id = 'tduserPicture'
rowspan='1' style='text-align:left' runat='server'>
<img ID='Imagess2' runat='server' src='http://img.youtube.com/vi/1bI8pGLBagY/0.jpg' Height='80px' Width='100px' /alt='image'>
<br/> www.youtube.com/watch?v=1bI8pGLBagY </td> </tr></table>&feature=em-hot
by Kevin Ayson 3,607,584 views <br/> ------------------------------------------------------------------- <br/> end of text
I need to add a checkbox in a html table I know the usual method like
<td>
<input type="checkbox" name ="chk1" />
</td>
My current code is
string html="";
html += "<table>";
html += "<tr><th>" + "A" + "</th><th>" + "B" + "</th><th>" + "C" + </th></tr>";
html += "<tr><td>" + "0" + "</td><td>" + "1" + "</td><td>" + "2" + </td></td>+"<input type="checkbox" name ="chk1" /> " +</td> </tr>";
html += "</table>";
but this gives an error
You have missed some quotes
please use this code
string html="";
html += "<table>";
html += "<tr><th>" + "A" + "</th><th>" + "B" + "</th><th>" + "C" + "</th></tr>";
html += "<tr><td>" + "0" + "</td><td>" + "1" + "</td><td>" + "2" + "</td></td>"+"<input type='checkbox' name ='chk1' /> " +"</td> </tr>";
html += "</table>";
It appears that you're missing a quote, also you can get rid of some of the quotes (and rows):
string html="";
html += "<table>";
html += "<tr><th>A</th><th>B</th><th>C</th></tr>";
html += "<tr><td>0</td><td>1</td><td>2</td></td><input type=\"checkbox\" name =\"chk1\" /></td></tr>";
html += "</table>";
No need of concatenations, just put single quotes outside as given in the example below:
string html = '';
html += '<table>';
html += '<tr><th>A</th><th>A</th><th>C</th></tr>';
html += '<tr><td>0</td><td>1</td><td>2</td></td><input type="checkbox" name ="chk1" /></td></tr>';
html += '</table>';