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 16 2006

eBay Selling Starter Kit for VB.NET In Town!!

Category: ASP.NET 2.0 - GeneralBil@l @ 11:43

You can now download the Ebay Starter Kit from: http://developer.ebay.com/windows/starterkits/

There is also an article at MSDN that helps you start your way with that starter kit, check it at:
Introduction to the eBay Selling Starter Kit

 

Hope that helps,

Regards

Tags:

Feb 15 2006

Dynamic Sql Query with Output Parameters

Category: Databases & SQLBil@l @ 14:13

I had a previous post on how to use Dynamic Sql Queries.

Today I had the need to create a Stored Procedure that returns an Output Parameter, where the value of the output parameter is set inside the Dynamic Query.

So here is a sample Stored Procedure that shows how to do s:

CREATE PROCEDURE GetNotificationIdByCustomerId
(
    @CustomerId    INT,
    @GroupId    INT,
    @NotificationId    INT OUTPUT
)
AS
BEGIN
    DECLARE @strQuery NVARCHAR(4000)
    DECLARE @parameterList NVARCHAR(4000)

    SELECT @strQuery = 
        N'SELECT 
            TOP 1 @NotificationId = NotificationId  
        FROM 
            Notifications
        WHERE (CustomerId = @CustomerId)  AND (Processed = 0) '

    IF ( @GroupId <> -1 )
    BEGIN
        SELECT @strQuery = @strQuery  + N' AND (GroupId = @GroupId)'
    END
    
    SELECT @parameterList =   N'@NotificationId INT OUTPUT, @CustomerId INT, @GroupId INT'            
    EXECUTE SP_EXECUTESQL @strQuery, @parameterList, @NotificationId OUTPUT, 
                @CustomerId = @CustomerId, @GroupId = @GroupId
END
GO

I need to get @NotificationId, which is set inside the dynamic query, I then supply a list of parameters inside the @parameterList, where I specify the output parameter.

Hope that helps,

Regards

Tags:

Feb 14 2006

Working with DotNetNuke Custom Modules

Category: DotNetNukeBil@l @ 17:36

I have recently started working with DotNetNuke, this is my first post in the DotNetNuke category, so expect I will be posting more often here in this section.

To start with, I would like to point all DNN developers about a great link where they can download CodeSmith Templates for creating DotNetNuke Modules.

You can visit: VS.NET 2003 Project Templates for DotNetNuke to download the templates you can use to create a new module. 

You can alos check this great article, that helps you out develop your first Module in DotNetNuke 3.x, located at: DotNetNuke Random Image Module - Tutorial

That was my start with Custom Modules or Private Assemblies in DotNetNuke.

Enjoy DotNetNuking !!

Regards

Tags:

Feb 14 2006

Build a Data Access Layer in less than 15 minutes with CodeSmith

Category:Bil@l @ 17:08

Erick Smith, the founder of CodeSmith, posted a great article on how to create a Data Access Layer in a very quick time.

You can check the article at: Build a Data Access Layer in less than 15 minutes

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

Access Selected GridViewRow in GridView

Category: ASP.NET 2.0 - GeneralBil@l @ 08:10

Hello:

I was working last night around 3:00 AM, and I found out that in my GridView Column's list, I have added a TemplateField of type LinkButton with CommandName=”EditRec”, in such a way, when the Edit link button is clicked, I want to access the selected GridViewRow, then populate a web form on the same page, and without having to show the “Update” and “Cancel” buttons on the GridView.

I did that, but the problem was now how to access the GridViewRow in the RowCommand method?

I used the “SelectedRow” property but I kept having “Object Reference not ....” I didn't know in fact.

I tried to use GridView1.Rows[e.CommandArgument], but the DataKey I set for the GridView was of type String, so cannot use that either.

I finally was able to use the following and it works fine for me:

if (e.CommandName.Equals("EditRec"))
  {
            string MediaIndex = e.CommandArgument.ToString();

            // Get the last name of the selected author from the appropriate
            // cell in the GridView control.
            GridViewRow selectedRow = (GridViewRow)(((Control)e.CommandSource).NamingContainer);

            string _mediaType   = selectedRow.Cells[0].Text;
            string _CheckOut    = selectedRow.Cells[1].Text;
}

                

The way the code works if as follows:

e.CommandSource -> LinkButton
((Control)e.CommandSource).NamingContainer -> GridViewRow

Then, simply use the Cells property inside the GridViewRow to access all cells.

Hope that Helps,

Regards

Tags: