Feb 19 2006

Password TextBox and PostBack

Sometimes in an ASP.NET (1.x/2.x) webform, we might have a Password TextBox, and one of the DropDownLists or RadiobuttonLists or any control present inside the web form might do a postback before you need to submit the form.

Every time this happens, I loose the Password TextBox value. A solution that might help you preserve the Password Textbox value upon postback is to add the following line inside the Page_Load event handler, so that they execute AT EVERY PAGE EXECUTION:

// Refill Password field
this.txtPassword.Attributes.Add("value", this.txtPassword.Text);

Hope this helps,

Regards

Tags: , ,

Feb 17 2006

Consume .Net WebService in ASP 3.0

Category: ASP.NET 1.xBil@l @ 19:12

I had the need this week to integrate a .Net WebService with an old ASP 2.0 web application at work.

I passed through tough times in fact, and that is why, I want to post here to help everyone who might need to consume a .Net WebService in ASP 2.0 applications.

The following code would access the .Net WebService by sending a request and receive a response:

 

Function EncryptText (Value)
    Dim DataToSend, xmlhttp, postUrl, XMLDOM, XMLNode
    DataToSend="value="& Value
    postUrl = "http://mysite.com/Security.asmx/EncodeString"
    Set xmlhttp = server.Createobject("MSXML2.XMLHTTP")
    xmlhttp.Open "POST",postUrl,false
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

    xmlhttp.send DataToSend
    
    Set XMLDOM = Server.CreateObject("Microsoft.XMLDOM")
    XMLDOM.Load(xmlhttp.responseBody)
    Set XMLNode = XMLDOM.SelectSingleNode("//string")
    
    If Not XMLNode Is Nothing Then
        EncryptText = XMLNode.Text
    End If        
End Function


First of all, we prepare the URL of the WebSerivce, then require a POST request, using the MsXml component that comes from Microsoft. We then set the RequestHeader of the request to "application/x-www-form-urlencoded", which is needed to be able to send the QueryStrings which are the parameters to the method being called in the WebService.

Then, we receive the Response from the webservice, fill it in an XML document, and then use XPath to get the returned result.

Web Services in .NET 1.1 has by default HttpGet and HttpPut turned off, contrary to .NET 1.0 and that is for sure a security issue.

You need to turn on the HttpGet and HttpPut inside the web.config of the WebService itself to be able to execute the code above, since we are sending a POST request.

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>

If your ASP 3.0 application that is calling the webservice is stored locally, then no need to enable anything, it works just fine.

Hope that helps you.

Regards

Tags:

Feb 12 2006

DataList Show/Hide Table Rows

Category: ASP.NET 1.x | ASP.NET 2.0 - GeneralBil@l @ 00:31

In the last few days, I was working on a Custom DotNetNuke Module, which is called ContactUs, which I will be using in one of the projects currently under my hands.

I wanted to list all entries of the ContactUs form that are stored in the database. So I decided to use the DataList, in which I place my own Table inside the ItemTemplate.

There are some fields in the ContactUs form that might be empty or null. So I didn't want to show the ROW inside the table for each NULL field in the database.

Here how I did it:

<asp:datalist id="dlstContactUs" runat="server" cellpadding="4" datakeyfield="itemId">
    <ItemTemplate>
        <table cellSpacing="0" cellPadding="2" border="0">
            <tr vAlign="top" runat="server" id="trCompany" Visible='<%# IsNull(DataBinder.Eval(Container.DataItem,"Company")) %>'>
               </tr>
        </table>
    </ItemTemplate>
</asp:datalist>

Watch the DarkGreen areas above.

In the code-behind, this is the IsNull method that I am using:

public bool IsNull(object item)
{
    if ((item.ToString() != null) && (item.ToString() != String.Empty))
    {
        return true;
    }
        return false;
}

Hope that helps,

Regards

Tags: ,

Feb 11 2006

CountryList SQL Script

I am working on a Custom DotNetNuke module. I wanted to have a DropDownList of all the countries in the world.

I had to google a little bit to find all the countries available, which I beleive are 222 countries.

I wanted to share with you the SQL Script I created.

You can download this script from the Files Area.

When you run this script using the Sql Query Analyzer, it will create the following:

  • regionList table
  • countryList table
  • Insert 222 countries into the countryList table categorized by regions located at regionList table.

I am sure you will need this script in your work some time.

If there is still any country not listed, please let me know so that I update the script

For DNN Custom Modules' developers, I found later on that there is a dll in the bind folder of the DNN installation called CountryListBox, don't know what it is, but I guess it is related to country list or so.

Hope this helps,

Regards

 

Tags: , ,

Feb 9 2006

Popup Window inside Code-Behind

Category: ASP.NET 1.xBil@l @ 14:14

Opening a pop up windows from code-behind has been the topic of many many questions on the ASP.NET forums. I once created a control in two versions for ASP.NET 1.1 and 2.0, that helps developers by calling a simple method, providing it with some paramters, and here you go, opening a popup windows very easily, no javascript no nothing, just simple VB.NET/C# function calls.

I had that control on my previous website, as a free downloadable control, I decided today to place it again on this blog, since there are still many developers on the ASP.NET forums, asking on how to do so.

Visit the Files Area on my blog and download the control and use it for free.

Enjoy Popupping !! :)

Regards

 

Tags:

Feb 8 2006

Good Links to Share

Category: ASP.NET 1.x | ASP.NET 2.0 - GeneralBil@l @ 08:01

I would like to share with you the following two links, which I beleive are good and useful.

Regards

 

Tags: ,

Jan 14 2006

Unable to Start Debugging on the Server. You do not have permission to debug

Category: ASP.NET 1.x | ASP.NET 2.0 - GeneralBil@l @ 20:46

Have you ever faced that error before?

I have started development lately on a Windows 2003 Standard Server, having both VS.NET 2003 and VS.NET 2005 installed.

I was trying to open a DotNetNuke project yesterday and got the error by VS.NET 2003:

Error while trying to run the project  : Unable to Start debugging on the web server. You do not have permissions to debug the server
Verify that you are a member of the 'Debugger Users' group on the server

I have Integrated Security on, Network Service, ASPNET, Administrator (Local Account), IUSR_MachineName accounts all added in the Debugger Users group.

Lately, I figured out after reading this document, How To Solve Debugger Problems

If you created the web project with a full machine name (like “machinename.domainname.something”), the web site is recognized as “Internet” site.
So the default setting of IE will impact on the behavior of log on. In this case, you need to enable logging on with your current user account in “Internet” area with IE setting.

But it is not the default setting of IE, so you’d be better off if you create project with only the machine name.

 

So, open the IE browser, go to --> Tools --> Internet Options --> Security --> Custom Level --> User Authentication --> Select Automatic Logon with current username/password

 

This will hopefully, fix your problem.

 

Regards

Tags: ,

Jan 12 2006

Bit Column in Microsoft SQL Server

Category: ASP.NET 1.x | ASP.NET 2.0 - GeneralBil@l @ 07:57

In my work today, I faced a very weird thingy, here it is:

I was retreiving a bit column from the table whose default value is set to 0, and then using an SqlDataReader, and the weird thing is that I used:

1- (bool)reader[col]
2- Convert.ToBoolean(reader[col]])
3- reader.GetInt32(col)

Nothing worked but:

Convert.ToBoolean( Convert.ToByte( reader[col] ) )

Can anyone explain why that happened? I beleive, option #1 should work pretty simple.

Regards

Tags: ,

Jan 12 2006

Visual Studio .NET and Class Libraries

Category: ASP.NET 1.x | ASP.NET 2.0 - GeneralBil@l @ 04:31

When I start a new project, I usually create a Blank Solution in VS.NET, then add to it my Class Libraries and Web Application. The problem I used to have before is that, every time I did some changes in one of the Class Libraries I had to update the references manually to all other projects referencing that updated Class Libraries.

Thank to Peter Johnson for hinting for me that:

Correct way:
1. Right-click web project file, choose "Add Reference..."
2. Click "Projects" tab.
3. Select your class library project and hit OK.

Wrong way:
1. Right-click web project file, choose "Add Reference..."
2. On ".NET" or "Browse" or "Recent" tabs, choose your class library output DLL.

Hope that helps you out.

This way, whenever you change anything in your Class Libraries, then you do a Build, all the references will be updated.

Regards

 

Tags: ,

Jan 6 2006

Visual Studio 2003 + HTTP/1.1 403 Forbidden

Category: ASP.NET 1.xBil@l @ 19:07

Before I create a new web application in Visual Studio .NET 2003, I usually create a new website in IIS MMC, then create the new web application based on the url of teh website I created early.

Today, doing the same process as above generated the following error:

The web server reported the following error when attempting to create or open the Web Project located at  the following URL: '....' . 'HTTP/1.1 403 Forbidden'

If you ever face such a problem, make sure in the website's properties screen in IIS MMC, in the Home Directory Tab, Execute Permissions is 'Script Only', since by default it will be 'None'.

Regards

Tags: