Sunday, April 26, 2009

Finding All Controls on Page in Asp.net

To find all controls on Page, including child controls. i.e. Loop through all control list.

Example: I have a page with Controls on Page, Pannel Controls (Which contains Few more child controls). Now I want to find list of all controls on Page including child control.

private void ListControlCollections()
    {
        ArrayList controlList = new ArrayList();
        AddControls(Page.Controls,controlList);

        foreach (string str in controlList)
        {
            Response.Write(str + "
");
        }
        Response.Write("Total Controls:" + controlList.Count);
    }

    private void AddControls(ControlCollection page,ArrayList controlList)
    {
        foreach (Control c in page)
        {
            if (c.ID != null)
            {
                controlList.Add(c.ID);
            }
           
            if(c.HasControls())
            {
                AddControls(c.Controls, controlList);
            }
        }
    }

Saturday, April 25, 2009

Multiple Querystring for Url Rewriting Asp.net

How to Handle Multiple Querystring for Url Rewriting in Asp.net

Please go through my earlier article on Url Rewriting.
@Update to my earlier article on Simplest Way to write Url Rewriting

If you have gone through my earlier article

<rewriter>
<rewrite url="~/Article/(.+)-(.+)-(.+).aspx" to="~/DynamicPage.aspx?MyTitleId=$2&CategoryId=$3">
</rewriter>


In Web.Config file you can handle special character by replacing it with its code.
Example in our case we have replace & with &

After making changes to web.config file you need to pass third argument as category Id, and that its. Your code is ready to handle multiple querystring argument.