0

Does anyone knows How to add ASP.NET control for <i></i> tags?
i am looking for ASP.NET Control that is equivalent with <i> Html tag

in my case, I also want to implement .FindControl() method for it inside the .cs file.
Here's the part of the code..


Example.axcs

<asp:Panel id="forDiv" CssClass="input-group colorpicker-component" runat="server">
                        <asp:TextBox ID="txtHeree" class="form-control" runat="server" Style="width: auto"></asp:TextBox>
                        <asp:Panel CssClass="input-group-append" runat="server">
                            <asp:Label CssClass="input-group-addon input-group-text" runat="server"><i></i></asp:Label>
                        </asp:Panel>
</asp:Panel>


from the code above, the FindControl method that I have implemented goes like this,


Example.ascx.cs

TextBox txtVal = e.Row.FindControl("txtHeree") as TextBox;
Panel txtVal = e.Row.FindControl("forDiv") as Panel;

and, etc..


My current problem is, I still can't find both the equivalent ASP.NET Control for <i></i> tags and also for .FindControl() method for it.
sure, I have read the reference to another QnA forum from both Stackoverflow and Microsoft Docs:
ASP.NET Control to HTML tag equivalent
and
https://learn.microsoft.com/en-us/troubleshoot/developer/webapps/aspnet/development/server-controls

ANY suggestion, answer, or efficient code for the <i></i> tag control, will be very.. very helpful.

Thank You.

4
  • There is no I aspnet control. It is just the old Italic html tag. You can do this with css. Commented May 25, 2022 at 7:12
  • @VDWWD how does it work? can you give me a short example or maybe the alternatives for this kind of case? thx. Commented May 25, 2022 at 7:18
  • Make a css class that makes text italic and add it to the CssClass property of a control. Commented May 25, 2022 at 7:30
  • if you add a "id" and runat=server tag, then that "<i>" control behaves quite much like any other server side asp.net control. See my example below. Commented May 25, 2022 at 8:30

1 Answer 1

0

Sure, if you add a "id" tag, and runat=server, then that "i" thing becomes quite much a server side control.

And doing that allows use in listview, repeaters etc.

So, do this:

        <i id="MyIguy" runat="server"></i>
        <br />

        <asp:Button ID="Button1" runat="server" Text="Button" 
            CssClass="btn" OnClick="Button1_Click" />

So, with code behind the button like this:

    protected void Button1_Click(object sender, EventArgs e)
    {
        MyIguy.InnerText = "this is fun";

    }

And we see this when run:

enter image description here

And say we use a gridview, repeater etc.?

say this markup, we just dropped in that (wiht id, and runat=server).

Quite much makes that control work, look, and feel like any other server side asp.net control.

Say, this markup and gridview (for the find control example).

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
            DataKeyNames="ID" CssClass="table" >
            <Columns>
                <asp:TemplateField HeaderText="Hotel Name"> <ItemTemplate>
                        <asp:Label ID="txtHotel" runat="server" Text='<%# Eval("HotelName") %>' ></asp:Label>
                    </ItemTemplate> </asp:TemplateField>

                <asp:TemplateField HeaderText="City"> <ItemTemplate>
                        <asp:Label ID="txtCity" runat="server" Text='<%# Eval("City") %>' ></asp:Label>
                    </ItemTemplate> </asp:TemplateField>

                <asp:TemplateField HeaderText="Description"> <ItemTemplate>
                        <i id="Descript" runat="server"> <%# Eval("Description") %>  </i>
                    </ItemTemplate> </asp:TemplateField>

                <asp:TemplateField HeaderText="View"> <ItemTemplate>
                    <asp:Button ID="Button1" runat="server" Text="View" 
                        CssClass="btn" OnClick="Button1_Click" />
                    </ItemTemplate> </asp:TemplateField>

            </Columns>
        </asp:GridView>

Code to load:

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DataSource = General.MyRst("SELECT * FROM tblHotelsA ORDER BY HotelName");
            GridView1.DataBind();
        }
    }

And we have this now:

enter image description here

And our view button click code, say this:

    protected void Button1_Click(object sender, EventArgs e)
    {
        Button btn = sender as Button;
        GridViewRow gRow = btn.NamingContainer as GridViewRow;

        int? PKID = GridView1.DataKeys[gRow.RowIndex]["ID"] as int?;

        Debug.Print("pk data base row id = " + PKID.ToString());
        Debug.Print("Row click index = " + gRow.RowIndex);

        // get hotel name
        Label txtHotel = gRow.FindControl("txtHotel") as Label;
        Debug.Print("Hotel name = " + txtHotel.Text);

        // get our <i> guy
        HtmlGenericControl myIthing = gRow.FindControl("Descript") as HtmlGenericControl;
        Debug.Print("Our i guy = " + myIthing.InnerText);

    }

Output :

enter image description here

so, most such controls - adding a "id" and runat="server", and at that point, it quite much behaves like most other asp.net controls.

Sign up to request clarification or add additional context in comments.

1 Comment

at some point, I don't show my complete code on this thread, and yet you give the detailed example using Griedview (and I am using it too). So, thanks.. But, just want to confirm, in the other hand, what if I use <asp:PlaceHolder ID="forITags" ..... ></asp:PlaceHolder> as the representation of <i></i> tags by controlling it from the .cs file using ...Controls.Add(new Literal() { Text = "<i></i>"}). is that doable also?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.