Showing posts with label Dot Net. Show all posts
Showing posts with label Dot Net. Show all posts

Thursday, March 21, 2013

TextboxWatermarkExtender and Textbox with TextMode = Password


I managed to do this by setting the watermark stylesheet to overlay an image in the textbox.
You simply take a snapshot of how you want the watermarked textbox to look, save that, then set the watermark css of that textbox to a style that displays the image and aligns the text to the right (because otherwise it will still be visible)
It's very easy and works flawlessly.
The Textbox:
<asp:TextBox ID="Password" runat="server" CssClass="txtbox_login" Width="120px" TextMode="Password">

The Watermark (Set the WatermarkText property to anything you want, but just one character):
<ajax:TextBoxWatermarkExtender ID="txtWMark2" runat="server" WatermarkCssClass="watermarked_psw"TargetControlID="Password" WatermarkText="*" />

The StyleSheet (You MUST align the text to the right, otherwise it will still display over the image):
.watermarked_psw
{
colorWhite;
font-familyTahoma;
font-size11px;
bordersolid 1px #a9a9a9;
text-indent:2px;
vertical-align:middle;
text-align:right;
background-image:url(../images/psw_wMark.png);
background-repeat:no-repeat;
}

I found this one here, by JeanT
It works !

Thursday, March 10, 2011

Download file from server

Download xlsx file from server
(already created)






public void GenerateXLSXFile(string fileName, ExcelDocument theDocument)
{
string filePath = Server.MapPath("~/TempFiles/" + fileName + ".xlsx");
theDocument.esd_WriteXLSXFile(filePath);

Response.Clear();
Response.AddHeader("Content-Type", "application/vnd.ms-excel");
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
Response.WriteFile(filePath);

Response.Flush();
System.IO.File.Delete(filePath);
Response.End();
}



Tuesday, August 31, 2010

Textbox validate characters digits only - Desktop App

I wanted to let the user enter onlydigits in a Textbox and validate the characters when the types.
I came up with this:





private void numericUpDown_Count_KeyPress(object sender, KeyPressEventArgs e)
{
if ("1234567890".IndexOf(e.KeyChar.ToString()) > 0)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}





tell me if there's an easier way :)

Tuesday, May 11, 2010

The ConnectionString property has not been initialized

I had this error:

The ConnectionString property has not been initialized.

I have a MSI installer, that is installed in our QA environment.

It was working before, and suddenly, I only had this error.
Googled up a bit, all this info on how to get the connection string and all that.

I finally realized that I rebuilt the whole solution, but I didn't rebuild the Deployment project. After a rebuild ... everything back to normal.

#:-S

Hope this helps someone.

Thursday, April 1, 2010

Gridview nowrap

What do you do when you have
AllowPaging="False" AllowSorting="False" AutoGenerateColumns="True" Width="800px" ShowHeader="true"

And it wraps all your data?

you add:

OnRowDataBound="GridView_RowDataBound"

and then:

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
}
}

Friday, September 19, 2008

Monthname in C# (C Sharp)

I think there's no Monthname (like is asp for ex. - which is weird)

But this is easy:

DateTime swTest = new DateTime(2000, 11, 1);
Page.Response.Write(swTest.ToString("MMMM"));

Monday, September 1, 2008

Calling a server side from client's Javascript

Did you ever need something like calling a server side thing from client's? Javascript ... ?

I think this is an easy way of doing that:





Response.Write ( " < script language="javascript"> function SetPmoR_Id() { document.all('" + lkbPmoRepAdd.ClientID + "').click(); } < / script>")

//or:

ClientScript.RegisterClientScriptBlock(this.GetType(), "somethn", " < script type='text/javascript'> function whatdoyouwannacalit() { try {document.all('" + yourlinkbutton.ClientID + "').click();} catch(e){} } < / script>");






what do you think?

you think there's an easier way? comment!