Tuesday, December 1, 2009

Identifying if a page is called from a popup

Situation:
I need to identify whether a page has been redirected from a popup window or it has been redirected from a full page, in order for me to perform a Redirect to "Main Menu" or "Close" from a button.

Solution:
1. Create two buttons (one that performs a PostBackUrl="/") and another one that executes (window.close() javascript event)

1 <asp:Button ID="cmdBackToMenu" runat="server" PostBackUrl="/" Text="Back to Main Menu" />
2 <asp:Button ID="cmdClose" runat="server" Text="Close" OnClientClick="window.close();"/>


2. Create a javascript event that will be called in the form.onload event.

1 <body bgcolor="#CCCCCC" onload="SettingButton();">



3. The javascript event should be able to identify whether a page was redirected from a popup window or from a full page and depending on the situation make visible or invisible the buttons created in the first step.

1 function SettingButton() {
2
3 if (opener) {
4 document.form1.cmdClose.style.visibility = "visible";
5 document.form1.cmdBackToMenu.style.visibility = "hidden";
6 }
7 else {
8 document.form1.cmdClose.style.visibility = "hidden";
9 document.form1.cmdBackToMenu.style.visibility = "visible";
10 }
11 }

Thursday, November 12, 2009

Cancelling default buttons when keypress enter

The javascript code :


1 function SaveTerms() {
2 if (window.event.keyCode == 13
) {
3 window.event.cancelBubble = true
;
4 window.event.returnValue = false
;
5 document.getElementById('ctl00_ContentPlaceHolder1_cmdSaveTerms'
).click();
6
}
7 }<




The button :

1 <asp:textbox id="txtPerc1" runat="server" cssclass="textbox_enabled2" readonly="False" width="58px" onkeypress="javascript:SaveTerms();"></asp:TextBox>

Tuesday, October 20, 2009

JavaScript

Some Javascript scripts that are always useful:

1) Disabling an item in a dropdown list:



2) Restriction in number of characters or lines in a multiline textbox



3) Blocking the right click / left click



To call it:
onMouseDown="whichButton(event)"

4) Cleaning the clipboard:

Encoding Problems

Sometimes we have trouble handling strange characters that must be transferred from one page to another. In general, should we have the habit of transferring strings using encode. In ASP.Net we do so like this:



To Recover this value, we do not need to do anything special just:



References:
http://msdn.microsoft.com/en-us/library/zttxte6w.aspx
http://www.w3.org/International/tutorials/tutorial-char-enc/

Friday, July 17, 2009

External Stylesheets issue in Telerik Reporting

Situation:
I was able to create an stylesheet, exported into an xml file and then referenced it into another report and even though I could see the styles in the designer, when I run my project the styles simply disappeared.

Solution 1:
In the page where the report is called add the following code (replace the path properly):


Dim ess As New Telerik.Reporting.Drawing.ExternalStyleSheet("..\StyleSheets\TahomaSmall.xml")
myReport.ExternalStyleSheets.Add(ess)
Me.ReportViewer1.Report = myReport


Solution 2:
Replace the path properly in the rpt.designer.vb
Me.ExternalStyleSheets.Add(New Telerik.Reporting.Drawing.ExternalStyleSheet("..\StyleSheets\TahomaSmall.xml"))


Issue cause:
Even though the report has a reference to the external stylesheet in its vb code if your report is not in the same directory as your stylesheet it has to be estated like that in the reference.

Telerik Reporting Report

Issue when deploying a report. If the error shows sth like this inside, just add this into the web.config file