Tag Archives: Literal

[RESOLVED] Loading a usercontrol into a webpage

Guys: asp.net c# question

I ma trying to load a usercontrol into a table. My usercontrol contains some literal controls.

I can't set the text of these literal controls to anythign, as in my code-behind of my control, whenever I try to access my controls, they come back as null.

My user control code:

<div style="color: Black; background-color: White;" mce_style="color: Black; background-color: White;">
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="OfferControl.ascx.cs"
Inherits="EOwner.Site.French.Controls.OfferControl" %>
<link rel="Stylesheet" href="../styles/OfferControl.css" type="text/css" />
<div id="all" style="background-color: #FFFFF0; height:100%;">
<div id="LeftPanel" style="float: left; width: 65%;">
<div id="title">
<asp:Literal ID="litTitle" runat="server" Text="TitleLabel"></asp:Literal>
</div>
<div id="Blurb">
<asp:Literal ID="litBlurb" runat="server" Text="BlurbLabel" ></asp:Literal>
</div>
<div id="Button">
<asp:ImageButton ID="btnViewOffer" runat="server"
ImageUrl="~/images/ViewOfferButton.jpg" ImageAlign="AbsMiddle" />
</div>
</div>
<div id="RightPanel" style="float: right; width: 35%;">
<div id="address">
<asp:Literal ID="litAddress" runat="server" Text="AddressLabel"></asp:Literal>
</div>
<div id="map">
Map
</div>
</div>
</div>

</div>


and the .cs

<div style="color: Black; background-color: White;" mce_style="color: Black; background-color: White;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EOwner.Contracts.Entities;

namespace EOwner.Site.French.Controls
{
public partial class OfferControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}

public Literal lit_Title
{
get { return litTitle; }
set { litTitle = value; }
}

public Literal lit_Blurb
{
get { return litBlurb; }
set { litBlurb = value; }
}

public Literal lit_Address
{
get { return litAddress; }
set { litAddress = value; }
}

public ImageButton btn_ViewOffer
{
get { return btnViewOffer; }
set { btnViewOffer = value; }
}
}
}
</div>



And the code that creates the control

 

 

<div style="color: Black; background-color: White;" mce_style="color: Black; background-color: White;">
foreach (OfferEntity o in offers)
{
OfferControl oc = new OfferControl();
oc.LoadControl("~/Controls/OfferControl.ascx");//GridViewRow gr = new GridViewRow(offers.IndexOf(o), offers.IndexOf(o), DataControlRowType.DataRow, DataControlRowState.Normal);
oc.ID = "oc_" + o.OfferId.ToString();
oc.Attributes.Add("OfferId", o.OfferId.ToString());
oc.lit_Title.Text = o.Title; //Request.QueryString["Title"].ToString();
oc.lit_Blurb.Text = o.Blurb;//Request.QueryString["Blurb"].ToString();
oc.btn_ViewOffer.Attributes.Add("OfferId", o.OfferId.ToString());
//address town postcode
oc.lit_Address.Text = o.Address + Environment.NewLine + o.Town + Environment.NewLine + o.Postcode + Environment.NewLine + o.WebAddress;

TableRow tr = new TableRow();
TableCell tc = new TableCell();
//pass in offer id, list is stored in the session, use the id in the usercontrol to get the data

tc.Controls.Add(oc);
tr.Cells.Add(tc);
tOffers.Rows.Add(tr);

//tbl.Rows.AddAt(gvOrderDetail.Rows.Count + 1, row);
}
</div>

 

Despite having the get/sets for every control, I can't seem to set the values of the controls, keep getting a nullreferenceexception. Even if I try to set the values of the controls in the usercontrol itself, I still can't access the controls.

Any pointers?


Andrew Berry - Software analyst/Developer

[RESOLVED] Can display graphics drawing image by using literal

i had draw a graph, however i want to display it.  can someone teach me, can display it to literal?

below is my coding:

 

 

    ' Create an in-memory bitmap where you will draw the image.
            ' The Bitmap is 300 pixels wide and 200 pixels high.
            myImage = New Bitmap(1200, 1200, pixelFormat.Format48bppRgb)

            ' Get the graphics context for the bitmap.
            g = Graphics.FromImage(myImage)


g.DrawString(I_fault_all2(i), New Font("Verdana", 12, FontStyle.Bold), Brushes.Black, xInterval * i + 50 + (width / 3), 500)
             

g.DrawString(I_total(i), New Font("Verdana", 12, FontStyle.Bold), Brushes.Black, xInterval * i + 50 + (width / 3), 500 - height - 25)
          

                '   Draw the axes
                g.DrawLine(Pens.Blue, 30, 10, 30, 500)         '   y-axis
                g.DrawLine(Pens.Brown, 20, 500, 490, 500)       '   x-axis


 

here is the coding i don't want as display as below, because it will go to a new screen without header and template.

Response.ContentType = "image/gif"


            ' Render the image to the HTML output stream.
            myImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)


To my knowledge, HTML does not currently have the capacity to accept an embedded binary stream and render it as an image.

You'd need to render an img tag whose src is pointing at a page (or handler or service, etc.) that streams back the desired image.

[RESOLVED] TextBox1 multiline how to display data in another row

Hi,


I have written the text in the textbox:
1. - test1
2. - test2
3. - test3


In Label1 appears as follows: 1 - test1 2 - test2 3 - test3

How to write so label1:
1. - test1
2. - test2
3. - test3


I want to show the same in label1 as shown textbox1


Regards,
Dejan

use as:

Label1.Text = "1 - test1 </br>2 - test2 </br>3 - test3";



Already however, the data are stored in textbox1 who has:
test1
test2
test3

If I do:
label1.text = textbox1.text, displayed in one line:
test1 test2 test3


I want to display in label1:
test1
test2
test3



Regards,

Dejan

hi,

you can use literal control

 

this.literal.Text = "Hello</br>Karthick";

 

Not work, write: test1 test2 test3


If the table is stored as follows:
test1
test2
test3

I want to see this text as well as in label1.

Is this possible?


Regards,

Dejan

programercek

Is this possible?

hi, as you are getting 3 rows from database use reader as:

while (dr.Read())
        {
            Label1.Text += dr[0].ToString() + "</br>";
        }



I checked your code, but not works:

SqlCommand comm = new SqlCommand("select Porocilo from tbl_PotniNalogi Where ID=" + Convert.ToInt32(Session["TiskanjeUredi"])+"", connectionString);
            comm.Connection.Open();
            SqlDataReader r1 =
                comm.ExecuteReader(CommandBehavior.CloseConnection);
            while (r1.Read())
            {
               // Console.WriteLine(r.GetString(0));

                lblPorocilo.Text += r1[0].ToString() + "</br>";  

            }
            r1.Close();
            connectionString.Close();



Result: test1 test2 test3

programercek

while (r1.Read())
            {
               // Console.WriteLine(r.GetString(0));

                lblPorocilo.Text += r1[0].ToString() + "</br>";  

            }
            r1.Close();
            connectionString.Close();

sorry instead of using label inside use as below:

string lblval=""; while (r1.Read())            {
                    lblval += r1[0].ToString() + "</br>";              }
            r1.Close();            connectionString.Close();
 lblPorocilo.Text = lblval;

It does not work.

Result is still: test1 test2 test3

textbox1 =
test1
test2
test3

Sorry for wrong code:

use <br> instead of </br> see below working code:

private void Page_Load(Object sender, EventArgs e)        {
            SqlConnection con = new SqlConnection("Data Source=localhost\\sqlexpress;Initial Catalog=test;Integrated Security=True");
            SqlCommand cmd = new SqlCommand("select weeknumber from Table_1", con);
            SqlDataReader dr;            con.Open();
            dr = cmd.ExecuteReader();            string aa = "";
            while (dr.Read())            {
                aa += dr[0].ToString() + " <br>";            }
            Label1.Text = aa;        }

[RESOLVED] How to change the font size of a span dynamically

I want to be able to change the font size of the span style dynamically depending on how many days in the month will be filled up. I am using a calendar object and if only 7 days are filled up so far I want to make the font larger for the user. As the month fills up more days and I want to make the font smaller, so it will all fit on the page better. Is there a way to do this?


Dim linkstr as string

linkStr = "<span style=""font-size:11pt; font-Weight:bold; color:white""><br />IN:  " & t_in & _
                                   "<br />OUT:  " & t_out & "<br /><br />Daily Hrs: " & t_hours & _
                                   "<br /><br />Wkly Hrs: " & total_hours_final & "<br />OT: " & over_time & "</span>"

e.Cell.Controls.Add(New LiteralControl(linkStr))


Using: Visual Web Developer 2008; Asp.net; VB.net Code; Access db


give the span id and try to access it in codebehind using spanid.

 

maxmax 

[RESOLVED] pdf file search over string or text

Dear all,

I want to seach pdf files using asp.net C#.

if any pdf file content is "albert"  list that all files


or


search file on the basis of its content

thanks!

Hi umeshjha.net,

You can use the following code to open the pdf file, and find whether the pdf file contain the "albert" words.

using iTextSharp.text.pdf;
using iTextSharp.text;
  
private void openPDF()
{
            string str = "";
            string newFile = "c:\\New Document.pdf";
            Document doc = new Document();
  
            PdfReader reader = new PdfReader("c:\\New Document.pdf");
            for (int i = 1; i <= reader.NumberOfPages; i++)
            {
                byte[] bt = reader.GetPageContent(i);
  
                str += ExtractTextFromPDFBytes(bt);
  
            }
}
  
  
 private string ExtractTextFromPDFBytes(byte[] input)
        {
            if (input == null || input.Length == 0) return "";
  
            try
            {
                string resultString = "";
  
                // Flag showing if we are we currently inside a text object
                bool inTextObject = false;
  
                // Flag showing if the next character is literal
                // e.g. '\\' to get a '\' character or '\(' to get '('
                bool nextLiteral = false;
  
                // () Bracket nesting level. Text appears inside ()
                int bracketDepth = 0;
  
                // Keep previous chars to get extract numbers etc.:
                char[] previousCharacters = new char[_numberOfCharsToKeep];
                for (int j = 0; j < _numberOfCharsToKeep; j++) previousCharacters[j] = ' ';
  
  
                for (int i = 0; i < input.Length; i++)
                {
                    char c = (char)input[i];
  
                    if (inTextObject)
                    {
                        // Position the text
                        if (bracketDepth == 0)
                        {
                            if (CheckToken(new string[] { "TD", "Td" }, previousCharacters))
                            {
                                resultString += "\n\r";
                            }
                            else
                            {
                                if (CheckToken(new string[] { "'", "T*", "\"" }, previousCharacters))
                                {
                                    resultString += "\n";
                                }
                                else
                                {
                                    if (CheckToken(new string[] { "Tj" }, previousCharacters))
                                    {
                                        resultString += " ";
                                    }
                                }
                            }
                        }
  
                        // End of a text object, also go to a new line.
                        if (bracketDepth == 0 &&
                            CheckToken(new string[] { "ET" }, previousCharacters))
                        {
  
                            inTextObject = false;
                            resultString += " ";
                        }
                        else
                        {
                            // Start outputting text
                            if ((c == '(') && (bracketDepth == 0) && (!nextLiteral))
                            {
                                bracketDepth = 1;
                            }
                            else
                            {
                                // Stop outputting text
                                if ((c == ')') && (bracketDepth == 1) && (!nextLiteral))
                                {
                                    bracketDepth = 0;
                                }
                                else
                                {
                                    // Just a normal text character:
                                    if (bracketDepth == 1)
                                    {
                                        // Only print out next character no matter what.
                                        // Do not interpret.
                                        if (c == '\\' && !nextLiteral)
                                        {
                                            nextLiteral = true;
                                        }
                                        else
                                        {
                                            if (((c >= ' ') && (c <= '~')) ||
                                                ((c >= 128) && (c < 255)))
                                            {
                                                resultString += c.ToString();
                                            }
  
                                            nextLiteral = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
  
                    // Store the recent characters for
                    // when we have to go back for a checking
                    for (int j = 0; j < _numberOfCharsToKeep - 1; j++)
                    {
                        previousCharacters[j] = previousCharacters[j + 1];
                    }
                    previousCharacters[_numberOfCharsToKeep - 1] = c;
  
                    // Start of a text object
                    if (!inTextObject && CheckToken(new string[] { "BT" }, previousCharacters))
                    {
                        inTextObject = true;
                    }
                }
                return resultString;
            }
            catch
            {
                return "";
            }
        }
  
 private bool CheckToken(string[] tokens, char[] recent)
   {
     foreach (string token in tokens)
       {
          if ((recent[_numberOfCharsToKeep - 3] == token[0]) &&
           (recent[_numberOfCharsToKeep - 2] == token[1]) &&
           ((recent[_numberOfCharsToKeep - 1] == ' ') ||
           (recent[_numberOfCharsToKeep - 1] == 0x0d) ||
           (recent[_numberOfCharsToKeep - 1] == 0x0a)) &&
           ((recent[_numberOfCharsToKeep - 4] == ' ') ||
           (recent[_numberOfCharsToKeep - 4] == 0x0d) ||
           (recent[_numberOfCharsToKeep - 4] == 0x0a))
                 )
           {
                    return true;
            }
            }
            return false;
        }


Please check the following link:

http://www.codeproject.com/KB/showcase/TallComponents.aspx