Wednesday, March 28, 2007

Cross Page Posting ASP .NET - alternative to long and complicated query strings

Scenario: in my application, I have a page where I search for records. Let's say user accounts. I type the user name in a TextBox and hit Search. the results are displayed. If there is no available result, I want an 'Add New User' button to appear on the page, button that redirects the user to the page where you can insert new users and fill in the fields with the info i searched for in the previous page.

I don't like large and more or less explicit querystrings. That is why for the Add New user burron I will not perform Response.Redirect("NewUser.aspx?username=" + txtUsername.Text). Plus, what if I have 10 fields on the search page? The length of the query string has a limit and so does my focus :)

The solution is easy: I should just redirect to New User and read the information from the Previous Page.

Zis si facut. (word by word translation not supported :) )

There are 4 steps:

1. the Add New user Button:
 < a s p : LinkButton ID =" lnkAdd" runat ="server" Visible ="False" PostBackUrl= "~ /NewUser.aspx" > Add New Patient < / asp : LinkButton>
2. the Search page code: add a public property that exposes the control(s) you want to look for when you are in the next page:
    public TextBox TxtName
    {
        get { return txtName;  }
    }
 

3. the New User page:
 < % @  PreviousPageType VirtualPath=" ~ / Search.aspx "  % >
4. the code
 if(PreviousPage.Title.Equals("Search"))
 {
            string name = PreviousPage.TxtName.Text;
 }

Posted by Madalina at 14:45:33 | Permanent Link | Comments (0) |

Web controls ASP .NET - alternative to long and complicated query strings

Scenario: in a web application, the user can edit an object. Depending on the user role, object state etc you only want to display some of the object fields on the page.

One of the solutions is to use query strings. Another is to user Session variables.
But the safest solution that does not interfiere with the security of the application or the memory on the server is the Web Control one: you build a web control that has some public properties that you assign values to in the page where you place the webcontrol: WebControl1.Type = "new"; When the web control is loaded, the code inside it reads the value of the variables and acts accordingly. This way, you avoid passing these values in the querystring or through state variables.

Maybe I haven't been that convincing in this post. However, if you know that working with many fields grouped into panels for an object that you can add/edit in more than one page, or by user roles that only have access to certain directories of the web application(thus implying the use of more than one page for the same action), you may find this solution as being your salvation :)

Posted by Madalina at 14:33:51 | Permanent Link | Comments (0) |

Friday, March 09, 2007

The truth about working in the IT industry

1. We work weird (night) shifts...
Just like prostitutes.

2. They pay you to make the client happy...
Just like a prostitute.

3. The client pays a lot of money, but your employer
keeps almost every penny...
Just like a prostitute.

4. You are rewarded for fulfilling the client's dreams...
Just like a prostitute.

5. Your friends fall apart and you end up hanging out
with people in the same profession as you...
Just like a prostitute.

6. When you have to meet the client you always have to
be perfectly groomed...
Just like a prostitute.

7. But when you go back home it seems like you are
coming back from hell...
Just like a prostitute.

8. The client always wants to pay less but expects
incredible things from you...
Just like a prostitute.

9. When people ask you about your job, you have
difficulties to explain it...
Just like a prostitute.

10. Everyday when you wake up, you say: "I'm not going
to spend the rest of my life doing this."
Just like a prostitute ........
Posted by Madalina at 09:40:22 | Permanent Link | Comments (0) |