Link to home
Start Free TrialLog in
Avatar of Dirar Abu Kteish
Dirar Abu KteishFlag for Palestine, State of

asked on

Removing table tage around login control

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
Avatar of DropZone
DropZone
Flag of United States of America image

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.
Avatar of Dirar Abu Kteish

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of DropZone
DropZone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello dZ,

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

-dirar
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
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
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
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.
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
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.
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
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.
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
Hi -dZ, I've posted a new question if you are interested to take a look at check

https://www.experts-exchange.com/questions/22772340/override-Login-Authentication-Function.html

Thanks