I've got an asp image in a repeater control, and I used the marked answer found here to get it so it links to the actual file:
Asp:Image with Link
Specifically, I surrounded it by an asp:hyperlink:
<asp:hyperlink id="link" runat="server">
<asp:image id="img" runat="server" imageurl="..." />
</asp:hyperlink>
This solution worked perfectly. However, when I tried to click on the link in IE, it immediately downloaded the image and then prompted me with options at the bottom to open or save the file.
Is there any way to have that hyperlink just open the image on a new page?
If you can use js:
<asp:HyperLink ID="link" runat="server">
<asp:Image ID="img" runat="server"
ImageUrl="~/images/app/your-img.png"
onclick="openWinPopUp(this.src)" />
</asp:HyperLink>
<script>
function openWinPopUp(URL, w, h, t, l) {
var wdh = (w == null || w == "" || w == "undefined") ? 250 : w;
var hgh = (h == null || h == "" || h == "undefined") ? 160 : h;
var tp = (t == null || t == "" || t == "undefined") ? 200 : t;
var lft = (l == null || l == "" || l == "undefined") ? 100 : l;
window.open(URL, "blank", "toolbar=no,location=no,directories=no," +
"status=no,menubar=no,scrollbars=yes," +
"resizable=no,copyhistory=no," +
"width=" + wdh + ", height=" + hgh + ", left =" + lft + "," +
"top = " + tp + ";");
}
</script>
Tested on MS Edge.
Related
Greeting everyone, I'm trying to do a windows form for collage were I can get the average of student scores. Seems like I have an issue with the divide function. here is my code , to see if you guys spot something wrong that could help me. I Appreciate in advance
private void getaveragebutton_Click(object sender, EventArgs e)
{
if (customTextboxes4.Texts == "" || customTextboxes5.Texts == "" || customTextboxes6.Texts == "" || customTextboxes7.Texts == "" || customTextboxes8.Texts == "" ||
customTextboxes9.Texts == "" || customTextboxes10.Texts == "" || customTextboxes11.Texts == "" || customTextboxes12.Texts == "" || customTextboxes13.Texts == ""
|| customTextboxes15.Texts == "" || customTextboxes16.Texts == "" || customTextboxes17.Texts == "" || customTextboxes18.Texts == "" || customTextboxes19.Texts == "" ||
customTextboxes20.Texts == "" || customTextboxes21.Texts == "" || customTextboxes22.Texts == "" || customTextboxes23.Texts == "" || customTextboxes24.Texts == "")
{
MessageBox.Show("Fill all the Boxes with Digits");
}
else
{
label4.Visible = true;
label5.Visible = true;
label7.Visible = true;
label61.Visible = true;
label28.Visible = true;
label29.Visible = true;
label30.Visible = true;
label31.Visible = true;
label45.Visible = true;
label46.Visible = true;
//short--test calculations
//students short test score variables
decimal a, b, c, d, e1, f, g, h, i, j;
//students short test value variables
decimal k, l, m, n, o, p, q, r, s, t;
//st results variables
decimal u, v;
decimal r1st;
decimal r2st;
decimal results;
//customboxes st score
a = Decimal.Parse(customTextboxes4.Texts);
b = Decimal.Parse(customTextboxes5.Texts);
c = Decimal.Parse(customTextboxes6.Texts);
d = Decimal.Parse(customTextboxes7.Texts);
e1 = Decimal.Parse(customTextboxes8.Texts);
f = Decimal.Parse(customTextboxes9.Texts);
g = Decimal.Parse(customTextboxes10.Texts);
h = Decimal.Parse(customTextboxes11.Texts);
i = Decimal.Parse(customTextboxes12.Texts);
j = Decimal.Parse(customTextboxes13.Texts);
//custom boxes st values
k = Decimal.Parse(customTextboxes15.Texts);
l = Decimal.Parse(customTextboxes16.Texts);
m = Decimal.Parse(customTextboxes17.Texts);
n = Decimal.Parse(customTextboxes18.Texts);
o = Decimal.Parse(customTextboxes19.Texts);
p = Decimal.Parse(customTextboxes20.Texts);
q = Decimal.Parse(customTextboxes21.Texts);
r = Decimal.Parse(customTextboxes22.Texts);
s = Decimal.Parse(customTextboxes23.Texts);
t = Decimal.Parse(customTextboxes24.Texts);
r1st = a + b + c + d + e1 + f + g + h + i + j;
r2st = k + l + m + n + o + p + q + r + s + t;
//st results variables definitions
u = Decimal.Parse(label28.Text);
v = Decimal.Parse(label29.Text);
//st result
label28.Text = r1st.ToString();
label29.Text = r2st.ToString();
results = u / v;
label4.Text = results.ToString();
return;
}
[enter image description here](https://i.stack.imgur.com/xu8cp.png)
Im trying to get all the score inserted in the text boxes to sum them. then get the results to Student Score and Total (That part is working for me) . After that divide the Student Score / Total to get the results in a hidden label that will be visible after getting the results. (that is the part that Im having issues with)
Well sorry to everyone for not following the proper way to post to get the proper help and thanks for those who let me know what to do for a next time to get the proper help. Also , thank you for explaining me the variable thing that was empty I really appreciate. Here is how I did fix my issue:
private void getaveragebutton_Click(object sender, EventArgs e)
{
if (customTextboxes4.Texts == "" || customTextboxes5.Texts == "" || customTextboxes6.Texts == "" || customTextboxes7.Texts == "" || customTextboxes8.Texts == "" ||
customTextboxes9.Texts == "" || customTextboxes10.Texts == "" || customTextboxes11.Texts == "" || customTextboxes12.Texts == "" || customTextboxes13.Texts == ""
|| customTextboxes15.Texts == "" || customTextboxes16.Texts == "" || customTextboxes17.Texts == "" || customTextboxes18.Texts == "" || customTextboxes19.Texts == "" ||
customTextboxes20.Texts == "" || customTextboxes21.Texts == "" || customTextboxes22.Texts == "" || customTextboxes23.Texts == "" || customTextboxes24.Texts == "")
{
MessageBox.Show("Fill all the Boxes with Digits");
}
else
{
label4.Visible = true;
label5.Visible = true;
label7.Visible = true;
label61.Visible = true;
label28.Visible = true;
label29.Visible = true;
label30.Visible = true;
label31.Visible = true;
label45.Visible = true;
label46.Visible = true;
//short--test calculations
//students short test score variables
decimal studentscorebox1, studentscorebox2, studentscorebox3, studentscorebox4, studentscorebox5, studentscorebox6, studentscorebox7, studentscorebox8, studentscorebox9, studentscorebox10;
//students short test value variables
decimal studentshorttestvalue1, studentshorttestvalue2, studentshorttestvalue3, studentshorttestvalue4, studentshorttestvalue5, studentshorttestvalue6, studentshorttestvalue7, studentshorttestvalue8,
studentshorttestvalue9, studentshorttestvalue10;
//st results variables
decimal studentshortestoverallscore;
decimal shortestoverallvalue;
decimal shortestaverage;
//customboxes student short test scores
studentscorebox1 = Decimal.Parse(customTextboxes4.Texts);
studentscorebox2 = Decimal.Parse(customTextboxes5.Texts);
studentscorebox3 = Decimal.Parse(customTextboxes6.Texts);
studentscorebox4 = Decimal.Parse(customTextboxes7.Texts);
studentscorebox5 = Decimal.Parse(customTextboxes8.Texts);
studentscorebox6 = Decimal.Parse(customTextboxes9.Texts);
studentscorebox7 = Decimal.Parse(customTextboxes10.Texts);
studentscorebox8 = Decimal.Parse(customTextboxes11.Texts);
studentscorebox9 = Decimal.Parse(customTextboxes12.Texts);
studentscorebox10 = Decimal.Parse(customTextboxes13.Texts);
//student short test value
studentshorttestvalue1 = Decimal.Parse(customTextboxes15.Texts);
studentshorttestvalue2 = Decimal.Parse(customTextboxes16.Texts);
studentshorttestvalue3 = Decimal.Parse(customTextboxes17.Texts);
studentshorttestvalue4 = Decimal.Parse(customTextboxes18.Texts);
studentshorttestvalue5 = Decimal.Parse(customTextboxes19.Texts);
studentshorttestvalue6 = Decimal.Parse(customTextboxes20.Texts);
studentshorttestvalue7 = Decimal.Parse(customTextboxes21.Texts);
studentshorttestvalue8 = Decimal.Parse(customTextboxes22.Texts);
studentshorttestvalue9 = Decimal.Parse(customTextboxes23.Texts);
studentshorttestvalue10 = Decimal.Parse(customTextboxes24.Texts);
//Sumatory of Students scores and Sumatory of Test Value
studentshortestoverallscore = studentscorebox1 + studentscorebox2 + studentscorebox3 + studentscorebox4 + studentscorebox5 + studentscorebox6 + studentscorebox7 + studentscorebox8 + studentscorebox9 + studentscorebox10;
shortestoverallvalue = studentshorttestvalue1 + studentshorttestvalue2 + studentshorttestvalue3 + studentshorttestvalue4 + studentshorttestvalue5 + studentshorttestvalue6 + studentshorttestvalue7 +
studentshorttestvalue8 + studentshorttestvalue9 + studentshorttestvalue10;
//String Results to Labels
label28.Text = studentshortestoverallscore.ToString();
label29.Text = shortestoverallvalue.ToString();
//Get Average of Short Test
shortestaverage = studentshortestoverallscore / shortestoverallvalue * 100;
label4.Text = shortestaverage.ToString();
return;
}
}
I did a correction of the variable names to not get confused like I was advised in the first post , then I deleted some variables that were empty like someone here explained me (thanks). Finally I did a re order of how it should be calculated to get the average and got it working. thanks to all and if you see something that I can improve let me know. I really appreciate everyone and every single advise. Have a good day everyone.
You cannot convert label to decimal as long as label contains no value. You have to rearrange the lines as follows
//st result
label28.Text = r1st.ToString();
label29.Text = r2st.ToString();
u = Decimal.Parse(label28.Text);
v = Decimal.Parse(label29.Text);
results = u / v;
label4.Text = results.ToString();
return;
Am using an editable HTML datatable on my asp.net web page .Which look like this,
How to add validation on column Target, to receive only float values.?
Function (For enable edit):
function editRow(oTable, nRow) {
var aData = oTable.fnGetData(nRow);
var jqTds = $('>td', nRow);
jqTds[0].innerHTML = aData[0];
jqTds[1].innerHTML = aData[1];
jqTds[2].innerHTML = '<input type="text" id="Float" class="form-control" value="' + aData[2] + '">';
jqTds[3].innerHTML = '<a class="save-row" href="">Save</a>';
jqTds[4].innerHTML = '<a class="cancel-row" href="">Cancel</a>';
}
I tried to add keypress event on the textbox , but its not working.!
$('#Float').keypress(function (event) {
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57) && (event.which != 8)) {
event.preventDefault();
}
});
Am new to jquery so please help me solve this ?
Try:
onload =function(){
var ele = document.querySelectorAll('.number-only')[0];
ele.onkeypress = function(e) {
if(isNaN(this.value+""+String.fromCharCode(e.charCode)))
return false;
}
ele.onpaste = function(e){
e.preventDefault();
}
}
Note: Above code doesn't work for -ve values.
I have the following label with ids:
<asp:Label ID="FromName0" runat="server" Visible="true"></asp:Label>
<asp:Label ID="FromName1" runat="server" Visible="true"></asp:Label>
<asp:Label ID="FromName2" runat="server" Visible="true"></asp:Label>
<asp:Label ID="FromName3" runat="server" Visible="true"></asp:Label>
<asp:Label ID="FromName4" runat="server" Visible="true"></asp:Label>
I want to assign the values to the label ids using for loop.
I am using the following tags in c#:
for (int i = 0; i < count; i++)
{
var label = this.Controls.Find("FromName " + i, true) as Label;
label.Text = Session["DeliverAddress" + i].ToString();
}
But ‘Find’ shows error like below:
System.Web.UI.ControlCollections does not have the definition for ‘Find’. But I have already added ‘System.Web.UI’ dll file. Can anyone help me?
I am using dotnet framework 4.0.
Thanks in Advance.
You can do this like this
public Control[] FlattenHierachy(Control root)
{
List<Control> list = new List<Control>();
list.Add(root);
if (root.HasControls())
{
foreach (Control control in root.Controls)
{
list.AddRange(FlattenHierachy(control));
}
}
return list.ToArray();
}
and
protected void Page_Load(object sender, EventArgs e)
{
Control[] allControls = FlattenHierachy(Page);
foreach (Control control in allControls)
{
Label lbl = control as Label;
if (lbl != null && lbl.ID == "FromName0")
{
lbl.ID = "myid";//Do your like stuff
}
}
}
Just use : Here MSDN article about FindControl
//
// Summary:
// Searches the page naming container for a server control with the specified identifier.
//
// Parameters:
// id:
// The identifier for the control to be found.
//
// Returns:
// The specified control, or null if the specified control does not exist.
public override Control FindControl(string id);
Here how your code should look like. Just as advice check if the control is null or the session variable is null, this can give you an exception.
for (int i = 0; i < count; i++)
{
var label = FindControl("FromName " + i) as Label;
if(label == null || Session["DeliverAddress" + i] == null)
continue;
label.Text = Session["DeliverAddress" + i].ToString();
}
I have a variable prix that returns 5998 7510 8144 9458 10916 13214 and this list must be changed to 59,98 75,10 81,44 94,58 109,16 132,14
How can I do it. That is, add a , before the last 2 digits (from right) of each number ?
This is the C# code I've tried so far :
XDocument docxx = XDocument.Parse(Session["xmlrs" + z + ""].ToString());
//This now holds the set of all elements named field
try
{
XNamespace foobar = "http://www.april-technologies.com";
var prix = docxx.Descendants(foobar + "CotisationMensuelle").Select(x => new { CotisationMensuelle =(string)x}).ToList();
rpMyRepeater1.DataSource = prix;
rpMyRepeater1.DataBind();
}
catch(Exception ex) {}
and the C# Code is :
<asp:Repeater ID="rpMyRepeater1" ItemType="" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "CotisationMensuelle").ToString() %>
<br />
</ItemTemplate>
</asp:Repeater>
Not quite clear what you are asking as you code sample is unrelated to the list you have given as an eample. If you need to add a comma two letters from the end, try this,
string val = "7958";
string newVal = val.Insert(val.Length-2,",");
Console.WriteLine(newVal);
Try following:
XNamespace foobar = "http://www.april-technologies.com";
var prix = docxx.Descendants(foobar + "CotisationMensuelle").Select(x => new { CotisationMensuelle =(string)x}).ToList();
var newPrix = new List<string>();
foreach (var s in prix)
{
var s1 = s.CotisationMensuelle.Substring(0, s.CotisationMensuelle.Length - 2);
var s2 = s.CotisationMensuelle.Substring(s.CotisationMensuelle.Length - 2);
//add a comma before the last 2 digits (from right)
var s_total = s1 +","+ s2;
newPrix.Add(s_total);
}
rpMyRepeater1.DataSource = newPrix.Select(x => new {CotisationMensuelle = x}).ToList();
rpMyRepeater1.DataBind();
You could use DataBound event, for sample, in your page:
<asp:Repeater ID="rpMyRepeater1" ItemType="" runat="server" OnItemDataBound="rpMyRepeater1_ItemDataBound">
<ItemTemplate>
<asp:Literal ID="ltl" runat="server"></asp:Literal>
</ItemTemplate>
</asp:Repeater>
in your code behine:
int i = 0;
protected void rpMyRepeater1_ItemDataBound(object Sender, RepeaterItemEventArgs e)
{
// if the item on repeater is a item of data
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// get value
string value = DataBinder.Eval(e.Item.DataItem, "CotisationMensuelle").ToString();
// find literal
Literal ltl = (Literal)e.Item.FindControl("ltl");
// check if i < 2
if (i < 2)
{
// write value
ltl.Text = value;
//increase i
i++;
}
else
{
// write value and <br/>
ltl.Text = string.Format("{0}<br />", value);
// zero i
i = 0;
}
}
}
how about:
string data = "5998 7510 8144 9458 10916 13214";
string newValue = string.Join(" ",
from s in data.Split(' ')
select (double.Parse(s) / 100).ToString("0.00"));
//59,98 75,10 81,44 94,58 109,16 132,14
I've known many ways to limit the characters inputed inside the Textbox control or Freetextbox control.
How can I limit the character in each line (row) of FreeTextBox control???
For example, if the character in a line is 200, then it auto go to the next line
Best regard!
Hello this tricky way to handle by Javascript or JQuery..
Please follow below code for same with Jquery
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<asp:TextBox ID="txtData" CssClass="text-limit" runat="server" TextMode="MultiLine" style="width:500px; height:150px;"></asp:TextBox>
<script type="text/javascript">
var charactorPerLine = 20;
$(function () {
$(".text-limit").keydown(function (event) {
// Allow: backspace(8), delete(46), tab(9), escape(27) and enter(13)
if ($.inArray(event.keyCode, [46, 8, 9, 27, 13]) !== -1 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anything
return;
}
else {
if ($(this).val().lastIndexOf("\n") == -1) {
if ($(this).val().length >= charactorPerLine) {
$(this).val($(this).val() + "\n");
}
}
else {
if (($(this).val().length - $(this).val().lastIndexOf("\n")) >= charactorPerLine {
$(this).val($(this).val() + "\n");
}
}
}
});
});
</script>