My code is returning " rather than "
In .cs
public string openingVal
{
get
{
string opening = "";
opening += "\"openingHoursSpecification\": [";
opening += "{";
opening += "\"#type\": \"OpeningHoursSpecification\",";
opening += "\"dayOfWeek\": [";
opening += "\"Tuesday\",";
opening += "\"Wednesday\",";
opening += "\"Thursday\",";
opening += "\"Friday\",";
opening += "\"Saturday\"";
opening += "],";
opening += "\"opens\": \"09:00\",";
opening += "\"closes\": \"19:00\"";
opening += "}";
opening += "],";
return HttpUtility.HtmlDecode(opening);
}
}
In .aspx
<%:addressOpening.openingVal.Replace("quot;","\"") %>
Which then returns
"openingHoursSpecification": [{"#type": "OpeningHoursSpecification","dayOfWeek": ["Tuesday","Wednesday","Thursday","Friday","Saturday"],"opens": "09:00","closes": "19:00"}],
I've tried the HtmlDecode Utility, also using Replace. Both of which do nothing.
Am I losing my mind?
Related
When creating table at run time using qsqlquery the fields of the sqlite database table are declared by user, and using that I want to create a table at run time.
How can I do that in qsql cpp?
qsqlQuery qry;
qry.exec("CREATE TABLE xyz ....."); // ???
Is there a way to create database Table using models like qsqlTableModel?
A code from my project. Just copied and pasted as is, but I think it should be enough for you to understand how to achieve your goal.
bool SqlTableManager::createTable()
{
QString qs = "CREATE TABLE IF NOT EXISTS ";
qs += m_tableName + " (";
bool firstElem = true;
QString primaryKeys;
for (auto &&item : m_columns)
{
if (!firstElem)
qs += ", ";
firstElem = false;
qs += item.name + " " + item.type;
if (item.primary)
{
if (!primaryKeys.isEmpty())
primaryKeys += ", ";
primaryKeys += item.name;
}
}
if (!primaryKeys.isEmpty())
{
qs += ", PRIMARY KEY (";
qs += primaryKeys;
qs += ")";
}
qs += ")";
auto [q,r] = m_db->createQuery(qs);
if (!r || !q.exec())
{
setLastError(q.lastError());
return false;
}
else
{
clearLastError();
return true;
}
}
A CSV file containing Japanese characters (UTF-8 characterset) is created from server-side using ASP.NET.
Code:
public void ExportToCsv_Click(object sender, EventArgs e)
{
try
{
string sContents = string.Empty;
string sTemp;
for (int k = 1; k <= (ObjList.Columns.Count - 1); k++)
{
sContents += ObjList.HeaderRow.Cells[k].Text + ",";
}
sContents += "\r\n";
for (int i = 0; i <= (ObjList.Rows.Count - 1); i++)
{
for (int j = 1; j <= (ObjList.Columns.Count - 1); j++)
{
sTemp = (ObjList.Rows[i].Cells[j].Text.ToString());
if (sTemp == " ")
sTemp = "";
if (j < ObjList.Columns.Count - 1)
sTemp = (sTemp + ",");
sContents += sTemp;
}
sContents += "\r\n";
}
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-disposition", "attachment; filename=" + "partslist.csv");
Response.ContentType = "application/csv";
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8 ;
Response.Write(sContents);
Response.Flush();
Response.End();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
But, when this file is opened in Microsoft Excel 2003, it does not show file contents properly.
How to make excel to open such a file properly.
Help will be appreciated.
Just add \xfeff at the beginning.
Follow this procedure :
Menu -> Data -> GetExternal Data -> From Text
Select your csv using the file dialog
In the text import wizard, step 1, select "65001 : Unicode (UTF-8)" as file origin.
Excel uses SJIS(Shift JIS) as default encoding.
You could try converting UTF-8 to SJIS or creating CSV file with BOM in UTF-8.
I was able to open UTF-8 csv file with BOM.
protected void ImageButton16_Click(object sender, ImageClickEventArgs e)
{
if (Session["login"].ToString() == "true")
{
int i = 0;
foreach (DataListItem Item in DataList1.Items)
{
Label id = (Label)DataList1.Controls[i].FindControl("ID");
Label bidcount = (Label)DataList1.Controls[i].FindControl("Label7");
string email = Session["username"].ToString();
TextBox bid = (TextBox)DataList1.Controls[i].FindControl("TextBox1");
if (bid.Text != "")
{
if (int.Parse(bid.Text) < int.Parse(bidcount.Text))
{
String script = "<SCRIPT LANGUAGE='JavaScript'> ";
script += "AddConfirmbid()";
script += "</SCRIPT>";
Page.RegisterClientScriptBlock("ClientScript", script);
}
else
{
String script = "<SCRIPT LANGUAGE='JavaScript'> ";
script += "invalidbid()";
script += "</SCRIPT>";
Page.RegisterClientScriptBlock("ClientScript", script);
}
}
else
{
String script = "<SCRIPT LANGUAGE='JavaScript'> ";
script += "enterbid()";
script += "</SCRIPT>";
Page.RegisterClientScriptBlock("ClientScript", script);
}
i++;
}
}
else
{
String script = "<SCRIPT LANGUAGE='JavaScript'> ";
script += "login()";
script += "</SCRIPT>";
Page.RegisterClientScriptBlock("ClientScript", script);
}
}
Problem in your code that your are searching textbox in wrong way. I hope blow code will help you out to get textbox correct value.
foreach (DataListItem item in DataList1.Items)
{
TextBox bid = (TextBox)item.FindControl("TextBox1");
string text = bid .text;
// Do whatever you need with that string value here
}
The title is not informative enough, couldn't come up with something that will fit, so I will appreciate if someone will change it, or at least offer another one.
My question:
I have a page that shows a user's profile by his ID: (Consider the next page as an example)
In the above, there are 3 fields which are dynamic:
The user's name
The skin he is using
His profile image
I don't want to add labels around the whole page, and set them before the page loads, in order to present his info (there will be more fields).
I want something that will be easy to maintain for future changes.
What is the correct way of doing this?
Thanks, Guy
Please look at this code.
public void UserProfile(DataTable table)
{
try
{
String sr = string.Empty;
sr += "<html><body><table>";
for (int i = 0; i < table.Rows.Count; i++)
{
DataRow row = table.Rows[i];
{
sr += "<tr>";
for (int j = 0; j < table.Columns.Count; j++)
{
sr += "<td>";
sr += table.Columns[j].ColumnName;
sr += "</td>";
sr += "<td>";
sr += row.ItemArray[j];
sr += "</td>";
}
sr += "</tr>";
}
}
sr += "</table></body></html>";
System.Web.UI.WebControls.Literal ltr = new System.Web.UI.WebControls.Literal();
ltr.Text = sr;
this.Controls.Add(ltr);
}
catch (Exception ex)
{
}
}
Hope This helps.
I need to create an HTML button dynamically in my ASP.NET C# codebehind, I must insert this button in my literal control, I use following syntax:
literal.Text+=<button id=\"MyButton\" runat=\"server\" OnServerClick=\"MyButton_Click\">Click Me</Button>";
button is displayed, it causes postback but my server click function (MyButton_Click) is not called, what is going wrong here? I should certainly use a literal, can I use ASP.NET controls in my literal?
I want to call a function after this button causes postback, can I use another objects in my literal? I should certainly use literals
thanks for your answers, I have a lot of codes in my literal, something like this:
......
......
dynTable += "</td></tr>";
dynTable += "<tr><td></td></tr>";
dynTable += "<tr><td></td></tr>";
dynTable += "<tr><td></td></tr>";
dynTable += "<tr><td></td></tr>";
dynTable += "<tr><td align=\"left\">";
dynTable += "<button id=\"MyButton\" type=\"submit\" runat=\"server\" OnServerClick=\"MyButton_Click\">Foo</button>";
dynTable += "</tr></td> </table> ";
}
}
//=====================================
dynTable += " </td>";
dynTable += " </tr>";
dynTable += " </table>";
dynTable += " </td>";
dynTable += " </tr>";
dynTable += " </table>";
dynTable += " </td>";
dynTable += " </tr>";
}
dynTable += "</table>";
}
ReviewPlace.Text = dynTable;
ReviewPlace is my asp.net literal object
You can't add Server - Html/Web controls that way. You have to create an object of Control in Page_Init/Page_Load event and add it to PlaceHolder's Controls collection.
Add PlaceHolder1 control in markup (.aspx)
<form id="form1" runat="server">
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</form>
and write Page_Init handler,
protected void Page_Init(object sender, EventArgs e)
{
System.Web.UI.HtmlControls.HtmlButton button = new System.Web.UI.HtmlControls.HtmlButton();
button.InnerText = "OK";
//Event handler - Lambda (anonymous method) expression
button.ServerClick += (sa, ea) =>
{
Response.Write("button is pressed");
};
//Named Event handler
button.ServerClick += new EventHandler(button_ServerClick);
PlaceHolder1.Controls.Add(button);
}
void button_ServerClick(object sender, EventArgs e)
{
Response.Write("Another handler");
}
EDIT: I suggest you to use jQuery/JavaScript - ajax to request server resources instead of handling server-events if you wish/want to generate markup by hand. Alternative solution to this issue is to use Server constrols - especially GridView/ListView and I'm sure these controls and binding mechanism will solve that issue.
Another possibility is use of Table Server control. Have a look at sample:
//For ease of use I'v subclass the `TableRow`
public class Row : TableRow
{
public Row(int col)
{
for(int i=0;i<col;i++)
Cells.Add(new TableCell());
}
public TableCell this[int index]
{
get { return Cells[index]; }
}
}
and Page_Init code to populate Table object.
protected void Page_Init(object sender, EventArgs e)
{
Table table = new Table();
Row row1 = new Row(3);
row1[0].ColumnSpan = 3;
row1[0].Text = "Search";
table.Rows.Add(row1);
Row row2 = new Row(3);
row2[0].Text = "Enter keyword";
row2[1].Controls.Add(new TextBox());
table.Rows.Add(row2);
Row row3 = new Row(3);
row3[0].ColumnSpan = 3;
Button button = new Button();
button.Text = "Search";
button.Click += (sa, ea) => Response.Write("Button is pressed");
row3[0].Controls.Add(button);
table.Rows.Add(row3);
PlaceHolder1.Controls.Add(table);
}
As AVD points out, this isn't a very good idea.
However, if you do decide to continue down this path, you will need to post back by calling the client script function __doPostBack() function with the correct __EVENTTARGET and __EVENTARGUMENT properties set.
This SO post shows a quick and dirty hack workaround here for doing this, by placing a hidden asp:button on the screen, and then changing your code to call the hidden button click.