I have a Imagebutton.
<asp:ImageButton
OnClientClick="alert('Du hast nun das Jetzt-Spielen-Feature aktiviert. \r\nEs zeigt anderen Nutzern von RPone in der Online-Liste hinter deinem Namen an, dass du jetzt gerne ein neues RPG beginnen würdest.\n\rDies hält 30 Minuten und deaktiviert sich automatisch, wenn du es nicht vorher deaktivierst.')"
OnClick="linkBtnNowPlay_Click" ID="imgButtonNewPlay" ImageUrl="~/Images/star1.gif" runat="server" />
works like charm but
<asp:ImageButton OnClick="linkBtnNowPlay_Click" ID="imgButtonNewPlay" ImageUrl="~/Images/star1.gif" runat="server" />
and
imgButtonNewPlay.OnClientClick = "alert('test')";
on Serverside does not, why?
I must have it on server side because I must include an if statement before
Add a semi-colon after alert();
ASPX Engine adds the call to __doPostBack() after your client code, without semi-colon; they are not separated well.
You cannot call a javascript function directly like that from server side, you can add the following into your linkBtnNowPlay_Click method in code behind,
protected void linkBtnNowPlay_Click(object sender, EventArgs e){
Response.Write("<script>alert('test');</script>"); }
Related
Im trying to get info from my database into my html, and im almost there. but for some reason, when i tried something, it all went south, it doesnt want to grab anything, and i have no idea why. ill upload all of my code here. and yes, i know is messy.
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="home" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> Micha de Haan's Portfolio </title>
<link href="styles/main.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=0.8">
</head>
<body>
<form id="form1" runat="server">
<!-- Alles tussen de header is de balk bovenin -->
<header>
<div class="ijzerenman"> </div>
<div class="verzekering"><img src="styles/Logo.png" Width:="60px" height="60px"></div>
<h1>
<strong>Welkom op mijn portfolio</strong>
</h1>
<ul>
<asp:Panel ID="pnlMenu" runat="server"></asp:Panel>
<%-- <div class="current1"><li>Home</li></div>
<div class="orange"><li>Over mij</li></div>
<div class="red"><li>Logboek</li></div>
<div class="green"><li>Ervaring</li></div>
<div class="blue"><li>Familie</li></div>
1-tabel aanmaken 'menu' met kolommen id, titel, pageid, kleur
2- daarna vullen met bovenstaande paginas
3 - alle records ophalen en doorlopen
4 -tijdens doorlopen stroing itemsoptellen
string strMenu += String.Format( #"<div class=\"{0}\"><li>{2}</li></div>", strKleur, strPageId, strTitle);
5- strMenu in literalcontrol
6 - toevoegen aan panel
--%>
</ul>
<%
string pageId = Request.QueryString["pageId"];
if (pageId == null || pageId == "") pageId = "start";
%>
</header>
</form>
</body>
</html>
ASPX.CS
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pageId = Request.QueryString["pageid"];
//Vraagt de QueryString aan die in de url wordt aangegeven
if (pageId == null) pageId = "start";
// als de pageid Querystring niets is, dan is de pageId "start"
string connectionString = ConfigurationManager.ConnectionStrings["dbCon"].ConnectionString;
//zet de connectiestring "dbCon", zodat de gebruiker bij aanpasbare informatie kan
SqlConnection con = new SqlConnection(connectionString);
//maakt een nieuwe instantie aan van een SqlConnection. dit is een representatie van een open verbinding aan SQL Databases.
SqlCommand cmd = new SqlCommand("select * from Menu", con);
//een command die wordt gestuurd naar de database, die vraagt om * te selecten van Menu, waar de * con is, en Menu de Menu database.
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
//Representeert een set van commands en een database connectie die worden gebruikt om een DataSet ( Een "cache" van data in het geheugen ) en om een SQL Database te updaten.
DataSet dataSet = new DataSet();
// een "cache" van data in het geheugen
dataAdapter.Fill(dataSet);
//refresht en updated de rijen in een database
DataTable table = dataSet.Tables[0];
// pakt de tabels in de dataset, en loopt constant tot er geen tables meer te krijgen zijn.
String content = "";
//zet string content naar niets
foreach (DataRow row in table.Rows)// Voor elke rij in table.rows (alle rijen in de table) pakt hij de kleur, pageId en Titel, en zet ze inplaats van de nummers.
{
content += string.Format(#"<div class=""{0}""><li>{2}</li></div>", row["Kleur"], row["PageId"], row["Titel"]);
}
this.pnlMenu.Controls.Add(new LiteralControl(content));//zet de resultaten van de content string in het html bestand, waar de pnlMenu wordt gerefrenced.
}
}
It looks like you are missing the namespace in code behind, in this snippet the myProject namespace. It should look like this
using System;
namespace myProject
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
That should also be present in the aspx file header Inherits property
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="myProject.WebForm1" %>
You probably deleted some stuff by accident. It would be easiest to create a new page and copy-paste all the code.
I want to add a button to my login control but it won't let me. I guess the build in login class works in a different way.
<asp:login
ID="seamenLogin" runat="server"
TitleText="<strong>Inloggning till sjöläkarwebben. Läkarintyg enligt Manilakonventionen</strong>"
InstructionText="<br/>Förutsättningar för att använda systemet, ansökan om lösenord<br/>och mer information bl.a.
om Manila finns på sidan<br/><a href='http:'>http:</a><br/><br/>
Inloggning med <a class='linkbutton' href='https:/' (BankID, Mobil BankID, ...)</a><br/><br/><br/>
Inloggning med användarnamn och lösenord kan fortfarande användas men vi<br/>rekommenderar att du övergår till inloggning med e-legitimation redan nu.<br/><br/>"
UserNameLabelText="Användarnamn:"
PasswordRecoveryText="Har du glömt ditt lösenord?<br/>Här kan du beställa nytt. Det sänds i rekommenderat brev till din folkbokföringsadress."
HelpPageUrl="http://www.transportstyrelsen.se/sv/Om-webbplatsen/Inloggning-till-vara-fordonstjanster/E-legitimation/Problem-med-din-e-legitimation/"
<TitleTextStyle CssClass="heading1" HorizontalAlign="Left"/>
<LabelStyle CssClass="textboxnamn" HorizontalAlign="Left" Width="100px"/>
<InstructionTextStyle HorizontalAlign="Left" />
<LoginButtonStyle CssClass="loginbutton"/>
</asp:login>
How do I add a simple button to this code?
Try converting the legacy Login control to a Template instead.
There should be a small triangle in the right corner which you could click and it should say/go to "Convert to Template".
Then you are free to do whatever changed you want to the template. But remember to be careful not to remove or alter the controls which are already in the table too much from initial state.
Example.
I want to create an excel sheet from click of button.
These excel sheet will contain report which is generated on classic asp page. When user clicks on button then an excel sheet should be created which will have the same report as page have
This header works fine:
<%
Response.AddHeader "Content-Disposition", "attachment;filename=NOMBRE_ARCHIVO.xls"
Response.ContentType = "application/vnd.ms-excel"
%>
For small tables, try this example in html/javascript:
<html>
<body>
<table id="tabla" border="1">
<tr><th>Uno</th><td>1</td></tr>
<tr><th>Dos</th><td>2</td></tr>
</table>
<p>
<input type="button" onclick="javascript:exportarExcel('tabla');" value="Vamos al excel!">
</p>
</body>
<script type="text/javascript">
function exportarExcel(tabla){
var t = document.getElementById(tabla);
t.border = 1;
var html = t.outerHTML;
html = encodeURIComponent(html);
// problemas con el encoding!
// se puede usar base64_encode() en lugar de encodeURIComponent(html))
// ojo con encodeURIComponet() que está deprecada. lo mejor sería usar base64
window.open('data:application/vnd.ms-excel,' + html);
}
</script>
</html>
I have a PDF file on my FTP Server. I want to display the PDF file using ASP.Net.
I used google viewer in an iframe control:
<iframe src="http://docs.google.com/gview?url=ftp://samplepdf.com/sample.pdf" style="width:718px; height:700px;" frameborder="0"></iframe>
It worked perfectly while viewing pdfs from public servers. The problem is that I need to give ftp username and password for the pdf to be displayed on my asp.net page.
Any thoughts?
Thanks in advance
Edit:
I can use
url=ftp://username:pass#ftp.samplesite.com/...
but I dont want the username and password to be attached to the url.
I also tried this code:
<div><object data="ftp://username:pass#ftp.website.com/website.com/wwwroot/folderpath/test.pdf" type="application/pdf" width="800" height="1000"> alt : test.pdf </object> </div>
and it works well. Tho the ftp username and password are still shown in the page source. Any ideas? Thanks
es simplemente poner un: id="NombreCampo" y asignar igualmente un: runat="server" desde el código en el archivo .aspx, quedaría así:
< iframe id="NombreCampo" runat="server" width="400" height="500" style="border: none;">
eso sería lo visible al usuario en el código de la página.
desde el codigo de lado del servidor poner la cadena con el FTP:
NombreCampo.Src = "https://docs.google.com/viewer?url=ftp://nombreUsuario:pass#ftp.samplesite.com/" + NombreArchivo + " & embedded=true";
¡listo
How can I put TAB inside itens in selectbox's option itens?
I have:
<select>
<option>Tese - Teste de descrição</option>
<option>Mais um - De desc.</option>
<option>tabulação - Item de tabulação com info</option>
</select>
I wanna:
<select>
<option>Tese Teste de descrição</option>
<option>Mais um De desc.</option>
<option>tabulação Item de tabulação com info</option>
</select>
Update: Ok, vbTab or Chr(9) do it:
<select>
<option>Tese<% Response.Write Chr(9) & Chr(9) & Chr(9) %>Teste de descrição</option>
<option>Mais um<% Response.Write Chr(9) %>De desc.</option>
<option>tabulação<% Response.Write Chr(9) & Chr(9) %>Item de tabulação com info</option>
</select>
but I could only see it in source code. The browser isn't rendering it.
Unfortunately in HTML is not specified a TAB character.
In order to achieve the result you are looking for you can generate the options in the selection box padding with non breaking spaces ( ) the string where you were adding the vbTab. You can try this:
<%
Function Rpad (sValue, sPadchar, iLength)
Dim result=""
For i=0 to i=iLength - Len(sValue)
result = result & sPadchar
Next
Rpad=result
End Function
%>
<select>
<option><% Response.Write Rpad("Tese"," ",10) %>Teste de descriзгo</option>
<option><% Response.Write Rpad("Mais um"," ",10) %>De desc.</option>
<option><% Response.Write Rpad("tabulaзгo"," ",10) %>Item de tabulaзгo com info</option>
</select>
Sorry but I can't try if my code actually works so maybe you have to thweak it a little. I hope you get the sense of it.