?
Solved

Removing table tage around login control

Posted on 2007-08-11
14
Medium Priority
?
579 Views
Last Modified: 2011-09-20
I need to remove the table tag that is created automatically around the login control in ASP.Net. I found this http://www.sidesofmarch.com/index.php/archive/2006/05/05/removing-the-table-from-aspnet-controls-a-fully-working-version/

I added the class but I don't know what else to do, any help would be appreciated
thanks

-dirar
0
Comment
Question by:Dirar Abu Kteish
  • 9
  • 5
14 Comments
 
LVL 18

Expert Comment

by:DropZone
ID: 19676066
Well, that page gives you all you need to know in order to do it.  You extend the class with the code provided, then in your page templage, instead of using the ASP.NET Login control, you use your new extended class.

     -dZ.
0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 19678315
hello dZ,

Yes this is the part that I didn't understand, how can I use the new class instead of the login class? an example would help a lot.

Thanks
0
 
LVL 18

Accepted Solution

by:
DropZone earned 2000 total points
ID: 19678801
Ah, I see.  You need to do 2 things:  First, you register your control on the page with a namespace.  Second, you use your control instead of the new one you created.  Here is a sample registration directive for a page.  You put it at the top of the page:

<%@ Register TagPrefix="MyControls" Namespace="MyControl.NameSpace" Assembly="MyControll.Assembly" %>

You know how all ASP component tags start with <ASP:control>? Well, the ASP: part is the TagPrefix, and the compiler uses it to find which namespace and assembly it belongs to.  For all ASP built-in controls, its already pre-configured with the prefix ASP.  For custom controls, you need to register them, and use whatever prefix you want there.

The Namespace attribute points to the namespace where you put your control, and the assembly, well, that's the assembly (DLL) where the C# code-behind is stored.

For the second part, instead of using:

     <ASP:Login runat="server" ...>
     </ASP:Login>

you use your own:

    <MyControls:MyLogin runat="server" ...>
    </MyControls:MyLogin>

That's it! its that simple!

Here's a tutorial on making your own custom controls:
http://samples.gotdotnet.com/quickstart/aspplus/doc/webctrlauthoring.aspx

      -dZ.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 19679580
Hello dZ,

Thanks for the reply, I will give it a try tomorrow and let u know what happens

-dirar
0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 19681948
Well it worked but it seems that the code from the file didn't work, this is the output I am getting:
<div class=""><table id="shiko" cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse;"
      <tr
            <td
                <div id="main-container"
                    <div id="login-container"
                        <div id="login-area"
                            <div id="form-area"
                                <p
                                    <label for="shiko_UserName" id="shiko_UserNameLabel"User Name:</label
                                    &nbsp;<input name="shiko$UserName" type="text" value="a" id="shiko_UserName" /
                                    <span id="shiko_UserNameRequired" title="User Name is required." style="color:Red;visibility:hidden;"*</span
                                </p
                                <p
                                    <label for="shiko_Password" id="shiko_PasswordLabel"Password:</label
                                    &nbsp; <input name="shiko$Password" type="password" id="shiko_Password" /
                                    <span id="shiko_PasswordRequired" title="Password is required." style="color:Red;visibility:hidden;"*</span
                                </p
                                <p
                                    <input id="shiko_RememberMe" type="checkbox" name="shiko$RememberMe" /<label for="shiko_RememberMe"Remember me next time.</label
                                </p
                                <p
                                   
                                </p
                                <p
                                    <input type="submit" name="shiko$LoginButton" value="Log In" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;shiko$LoginButton&quot;, &quot;&quot;, true, &quot;Login1&quot;, &quot;&quot;, false, false))" id="shiko_LoginButton" class=" submit" /
                                </p
                            </div
                        </div
                    </div
                </div
            </td
      </tr
</table</div>

some how the Regular Expressions seems not working, I will try to fix this up if you have any ideas I would be glad to hear

-dirar
0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 19682108
Well it worked but it seems that the code from the file didn't work, this is the output I am getting:
<div class=""><table id="shiko" cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse;"
      <tr
            <td
                <div id="main-container"
                    <div id="login-container"
                        <div id="login-area"
                            <div id="form-area"
                                <p
                                    <label for="shiko_UserName" id="shiko_UserNameLabel"User Name:</label
                                    &nbsp;<input name="shiko$UserName" type="text" value="a" id="shiko_UserName" /
                                    <span id="shiko_UserNameRequired" title="User Name is required." style="color:Red;visibility:hidden;"*</span
                                </p
                                <p
                                    <label for="shiko_Password" id="shiko_PasswordLabel"Password:</label
                                    &nbsp; <input name="shiko$Password" type="password" id="shiko_Password" /
                                    <span id="shiko_PasswordRequired" title="Password is required." style="color:Red;visibility:hidden;"*</span
                                </p
                                <p
                                    <input id="shiko_RememberMe" type="checkbox" name="shiko$RememberMe" /<label for="shiko_RememberMe"Remember me next time.</label
                                </p
                                <p
                                   
                                </p
                                <p
                                    <input type="submit" name="shiko$LoginButton" value="Log In" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;shiko$LoginButton&quot;, &quot;&quot;, true, &quot;Login1&quot;, &quot;&quot;, false, false))" id="shiko_LoginButton" class=" submit" /
                                </p
                            </div
                        </div
                    </div
                </div
            </td
      </tr
</table</div>

some how the Regular Expressions seems not working, I will try to fix this up if you have any ideas I would be glad to hear

-dirar
0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 19682282
This is the Fix that is working for me:

     protected override void Render(HtmlTextWriter writer)
        {
            //write opening div
            writer.WriteBeginTag("div");
            writer.WriteAttribute("class", this.CssClass);
            writer.WriteAttribute("id", this.ID);
            writer.Write(HtmlTextWriter.TagRightChar);

            //get the rendered HTML
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            //render output to string
            base.RenderContents(hw);

            //remove tables
            string str = sb.ToString();
            //remove table, tr and td
            str = Regex.Replace(str, @"</?(?i:table|tr|td)(.|\n)*?>", String.Empty);
            writer.Write(str);
            //write closing div
            writer.WriteEndTag("div");
        }

dZ thanks for the help


-dirar
0
 
LVL 18

Expert Comment

by:DropZone
ID: 19682613
First off, this comment:
    "Second, you use your control instead of the new one you created."
should have been:
    "Second, you use your new control instead of the ASP built-in one."
But I guess you got that :)

Second, I'm sorry but I just noticed the stupid RegEx that they use in that page.  Apparently the author either forgot to include the proper regular expressions, or removed them for some reason.  As it stands, it will remove all closing angled-brackets from all tags (just as you discovered!).

Your regular expression should work, but it may be "greedy", so I suggest the following:

</?(?i:table|tr|td)([^>]|\n)*>

     Cheers!
     -dZ.
0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 19682759
Hello dz,

I am new to .Net and all the time I was trying to use a class I have in the App_Code instead of dlls. When noticed that I created a new class application, added the reference I needed and compiled.  Then I added the dll to my web site, it didn't work and it always wrote the code of the Control as it was text, then I discovered that there is something called Web Control Library, I read more about added the code, compiled and finally it worked.
I found this link http://www.ondotnet.com/pub/a/dotnet/excerpt/progaspdotnet_14/index2.html?page=1 which was very helpful in-case someone interested

I think the article is bad and doesn't describe things well, but at least it gives u an idea and direction

Thanks again

-dirar
0
 
LVL 18

Expert Comment

by:DropZone
ID: 19682809
Check out this site, it is very useful and teaches you the basics on how to create custom controls:

http://samples.gotdotnet.com/quickstart/aspplus/

      -dZ.
0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 19682855
I've seen that one too, moving from ASP to .Net is not easy as I thought it might be, lot of things has changed I guess
0
 
LVL 18

Expert Comment

by:DropZone
ID: 19682879
Yes, lots of things.  For one, the .NET Framework is based on an entire new paradigm.  My personal suggestion is that instead of porting your site to .NET, you re-design it and build it in .NET from the ground up.  This is almost always better, for non-trivial sites.

   Cheers!
   -dZ.
0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 19682927
I know, this is what I am doing now, I'm just finding it hard to separate the JS and ASP from the HTML code, but I think I'll get use to it.

Anyway, thanks for the help. I am sure I will be needing something else again very soon

-dirar
0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 19725174
Hi -dZ, I've posted a new question if you are interested to take a look at check

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22772340.html

Thanks
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question