Category Archives: Literal

Adding a PayPal button within content detail of MasterPages

How do you add a  PayPal button inside of a content detail of a master page.  Since a MasterPage automatically encapsulates and nests ALL of the code of its contentplaceholder, by definition...all design and coding in a contentplaceholder cannot encorporate a form.  This is true because w3 specs do not allow the nesting for forms.

 

Simple MasterPage
'  No form can exist in the rest of this page...because you cannot nest forms within forms.  Since ASP.NET is about to require the detail page to be within an asp.net form, it does not straightforwardly support any sequential forms in the detail page that follows


<form id="form1" runat="server">
	<asp:ContentPlaceHolder runat="server" id="ContentPlaceHolder2">
	Header  ' NO FORMS can go in HERE
	</asp:ContentPlaceHolder>


<asp:ContentPlaceHolder runat="server" id="ContentPlaceHolder1">
Main Content ' NO FORMS can go in HERE
</asp:ContentPlaceHolder>
</form>


'I could put a sequential form here...but this is the end of the webpage and back in the Master Page....nothing really left to do.


 

hi,

Can you place the PayPal butto before the ContentPlaceHolder or form1. We can have multiple forms on the page as long as only one of them has the runat="server" attribute.

No..

The entire purpose of a master detail page is such that the Master page contains the basic "frames (content)" layout.  ALL of the primary web content is in a contentplaceholder.  I don't see that as atypical.  99.9999% of all master/detail pages are arranged in this fashion.   

And a PayPal button is the tip of the iceburg.  There are literally thousands of normal cross-post applications in any normal web application out there where a form must reside within a content place holder. 

Hi,

According to your description ,I would like to suggest you to check the link below for the article which describes about how to include multiple form tags in an ASP.NET page.

http://www.codeproject.com/Articles/36071/Implementing-Non-ASP-NET-Posts-in-ASP-NET.aspx

Hope it can help you.

Thanks, unfortunately rewriting the worlds software code just so it will work with Microsoft is "RARELY" an option.   The problem with this rewrite is now it will ONLY will asp.net...it won't stand-alone anymore and work on its own.

[RESOLVED] creating hyperlinks dynamically.

I want to create hyperlink dynamically whenever i click the button below is my code

int j = 1;
        for (int i = 0; i < j; j++)
        {
            //HyperLink links = new HyperLink();
            HyperLink hplink = new HyperLink();
            hplink.NavigateUrl = "http://www.asp.net";
            hplink.Text = "Click Here" + "<br /><br />";
            ph.Controls.Add(hplink);
        }

but i am unable to get the hyperlinks dynamically because the loop is going infinite.

for (int i = 0; i < j; j++) 


--> for (int i = 0; i < j; i++) 


Replace j++ with i++, since i is your looping variable. 

Ya when i have done what you have said but i am getting only one hyperlink when i press the button,i want to createhyperlinks whenever i click the button, i mean how many times i click the button that many times i have to get hyperlink. 

Here is a way to do that


1;) in your aspx markup :

<body>
    <form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    <br />
    <asp:Literal runat="server" ID="LinksPlaceHolder" />
    </form>
</body>


2;) in the code-behind :

    protected void Button1_Click(object sender, EventArgs e)
        {
            LinksPlaceHolder.Text += "<a href=\"http://www.asp.net/\">go to the asp.net website</a><br/></br>";
        }


if this  is not what you want, explain exactly what your are trying to do


This video shows one way of doing something like that: http://www.asp.net/ajax/videos/how-to-dynamically-add-controls-to-a-web-page 

There is a major problem with creating a new hyperlink each time a button is pressed.  Dynamic controls have to be redrawn each time the page loads.  In order to redraw a different hyperlink each time a button is pressed you will need to have a lists of hyperlinks in a DataTable or HybridDictionary that create the hyperlinks each time the button click causes a postback.  Your redraw loop is close but it should use a For Each and loop through the collection of hyperlink data and draw a control for each one during the Page Init method.  In the button click simply add the new hyperlink data to the collection.  Dynamic controls are pain and should be avoided whenever possible. 

Are you saying about tables rows and columns and adding the control to column and generating whenever the button is clicked?? but i want to achieve with a for loop is it possible?? 

For example the DataTable would contain columns CONTROL_ID, URL, TEXT.  Each time the button is clicked you create a new row from the DataTable fill in the fields and add the row to the data and store it in the ViewState.  Each time the page load you read the DataTable with your for each Row loop and add your hyperlinks to the placeholder.  This will make sure the drawing is constant each time and you only have to debug the data is getting updated and added properly.   

I think a little bit of code can explain much than big sentences.

Invalid loop for (int i = 0; i < j; j++)  

Write loop 

>> for (int i = 0; i < j; i++)  

Hi,

Http is stateless, Dynamically created control can not maintain itself after postback.

If you dynamically add a HyperLink Control to the page during button click, be aware that every PostBack is a new Request .They need to be recreated each time the page loads.

Check this two links, they give you some example and explanation:

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Studio_.NET_2005/Q_23207581.html

http://forums.asp.net/t/1186195.aspx

Hope this can help you.

Here you have increamented j++, that should be i++. so in your case conditon not get false at any time so that is goes in infinate looks

change as per below code

int j = 1;
        for (int i = 0; i < j; i++)
        {
            //HyperLink links = new HyperLink();
            HyperLink hplink = new HyperLink();
            hplink.NavigateUrl = "http://www.asp.net";
            hplink.Text = "Click Here" + "<br /><br />";
            ph.Controls.Add(hplink);
        }


 

Please mark as answer if this is helps

 

[RESOLVED] scrollable text area

hi

in create user wizard i need a scrollable text area for term of use

i use GlobalResources for difrent languages

can u please let me know what shuold i use for a text area that be scrollable and also work with resources text

i also need to give little format to that text inside of scrollable control

any information?

thanks 

you can use a div to create a scrollable region on your page

<div style="height:400px; overflow-y:scroll;">

   put your content (or a Label control / Literal control) here.

</div>

Set the TextMode of the text box to the Multiline it will be an autoscroll textarea 

[RESOLVED] dynamically add checkboxes to a calendar control...

I want to add two checkboxes to selected days in a calendar control.  I can do that but I can not figure out how to get the checkboxes to fire an event.   I tried to get a button to fire and event by iterating through the panel without success either. Here is my code so far:

Thanks in advance,

Photon (Springfield, Missouri)

 

<%@ Page Title="" Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false" CodeFile="Caledar_Add.aspx.vb" Inherits="Admin_Caledar_Add" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    
    <div id="home">
     <div id="Div" runat="server" style="width: 810px; height: 500px;">
   <div id="sidebar">
       
               
                 <asp:Button ID="Button_GetCheckBox" runat="server" Text="Button" />
                 <asp:Label id="Label1" runat="server" />
             </div>
       
             <asp:Panel ID="Panel1" runat="server">
           
       
       
      <div id="content">
          <h3><font face="Verdana">Adding Custom Content to Calendar</font></h3>
          <asp:Calendar id="Calendar1" runat="server"
                    ondayrender="Calendar1_DayRender"
                    onselectionchanged="Date_Selected"
                    ShowGridLines="true"
                    BorderWidth="1"
                    Font-Names="Verdana"
                    Font-Size="9px"
                    Width="500px"
                    VisibleDate="01/01/2011"
                    TitleStyle-BackColor="Red"
                    TitleStyle-Font-Size="12px"
                    TitleStyle-Font-Bold="true"
                     DayStyle-VerticalAlign="Top"
                    DayStyle-Height="50px"
                    DayStyle-Width="14%"
                    SelectedDate="1/1/0001"
                    SelectedDayStyle-BackColor="Red" />
                </asp:Panel>
  
  </div>
  </div>
  </div>

</asp:Content>

 

'**Code Behind**
Partial Class Admin_Caledar_Add

    Inherits System.Web.UI.Page

    Dim holidays(12, 31) As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        holidays(1, 1) = "New Year's Day"
        holidays(1, 26) = "Australia Day"
        holidays(2, 2) = "Groundhog Day"
        holidays(2, 14) = "Valentine's Day"
        holidays(3, 17) = "St. Patrick's Day"
        holidays(4, 1) = "April Fool's Day"
        holidays(5, 1) = "May Day"
        holidays(6, 15) = "My Birthday"
        holidays(7, 15) = "My Anniversary"
        holidays(8, 15) = "My Mother's Birthday"
        holidays(9, 24) = "Autumnal Equinox"
        holidays(12, 26) = "Boxing Day"

    End Sub
   

    Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)

        Dim d As CalendarDay
        Dim c As TableCell

        d = e.Day
        c = e.Cell

        If d.IsOtherMonth Then
            c.Controls.Clear()
        Else
            Try
                Dim Hol As String = holidays(d.Date.Month, d.Date.Day)
                'Response.Write(Hol)
                If Hol <> "" Then
                   
                    Dim _checkbox_Delete As CheckBox = New CheckBox()
                    _checkbox_Delete.ID = "chkDynamicCheckBox_Delete"
                    _checkbox_Delete.Text = "Delete"
                    c.Controls.Add(New LiteralControl("<br>" + Hol.ToString + "<br/>"))
                    c.Controls.Add((_checkbox_Delete))
                   
                    AddHandler _checkbox_Delete.CheckedChanged, AddressOf _checkbox_Delete_CheckedChanged
                End If
            Catch exc As Exception
               
                Response.Write(exc.ToString())
            End Try
        End If
    End Sub

   


   

    Function _checkbox_Delete_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim objCheckbox = DirectCast(sender, CheckBox)
        Response.Write("test")
    End Function

   

    Protected Sub Button_GetCheckBox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_GetCheckBox.Click
        For Each ctl As Control In Panel1.Controls
    
            If TypeOf ctl Is CheckBox Then
                'CType(ctl,CheckBox).ID
                Response.Write("test")
            End If
        Next ctl

    End Sub


End Class

 

I haven't got a response  so I will try again in a more focused way.  I have created a calendar control using ASP.net visual studio express 2008.  In the dayrender event, I have dynamically created  checkboxes.  My problem is I am not able to fire an event through an event handler.  What am I not doing correctly?  Below is my code:

Thanks in advance,

Photon

 

<%@ Page Title="" Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false" CodeFile="testcalendar.aspx.vb" Inherits="Admin_testcalendar" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    <div id="content">
         
  <h3><font face="Verdana">Adding Custom Content to Calendar</font></h3>

    <asp:Calendar id="Calendar1" runat="server"
                    ondayrender="Calendar1_DayRender"
                    ShowGridLines="true"
                    BorderWidth="1"
                    Font-Names="Verdana"
                    Font-Size="9px"
                    Width="500px"
                    VisibleDate="01/01/2011"
                    TitleStyle-BackColor="Red"
                    TitleStyle-Font-Size="12px"
                    TitleStyle-Font-Bold="true"
                     DayStyle-VerticalAlign="Top"
                    DayStyle-Height="50px"
                    DayStyle-Width="14%"
                    SelectedDate="1/1/0001"
                    SelectedDayStyle-BackColor="Red" />
                   
    </div>

</asp:Content>

'***Code Behind****

Partial Class Admin_testcalendar
    Inherits System.Web.UI.Page

    Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
       
        e.Cell.Text = ""
        Dim c As New CheckBox()
        c.Text = e.Day.DayNumberText
        AddHandler c.CheckedChanged, AddressOf _checkbox_CheckedChanged
        c.AutoPostBack = True

        e.Cell.Controls.Add(c)

    End Sub

    Protected Sub _checkbox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim objCheckbox = DirectCast(sender, CheckBox)

        'this response.write does not fire when a checkbox is checked
        Response.Write("test")
    End Sub
End Class


 

 

 

 

Hi,

Photon

I have dynamically created  checkboxes.  My problem is I am not able to fire an event through an event handler.  What am I not doing correctly
 

When we dynamically add control in page. We should notice that in page_Init as well as page_load is the best period for us to add control.

Calendar1_DayRender evnet is a very later event in page life cycle. So "AddHandler c.CheckedChanged, AddressOf _checkbox_CheckedChanged" will not trigger the event.

Alternative way is to use Page.ClientScript.GetPostBackEventReference to add a postback event manually to checkbox.

Like:

protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["__EVENTTARGET"] != null)
            {
                Response.Write(Request.Form["__EVENTARGUMENT"]);
            }
        }


  protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            e.Cell.Text = "";
            CheckBox cb = new CheckBox();
            cb.ID = "cb_" + e.Day.Date.ToString();
            cb.Text = e.Day.DayNumberText;
            cb.Attributes["onclick"] = Page.ClientScript.GetPostBackEventReference(cb, "CheckChanged");  //add postback event(javascript)
           

            e.Cell.Controls.Add(cb);
        }


And also the calendar can not remain the checkbox checked state on postback, so you need to use some state management object to store the checkbox checked list and remain them manually.

Hope this can help you.

[RESOLVED] Access to master page's controls

I have a MasterPage that has a h2 tag. How can I access to this h2 form its Content Page?


Thank u

Hi,


You can't directly access the H2 tag, as it is a html control, it would need to be marked as runat=server.


Secondly, you wouldn't be able to access it from the content page as it is in the master pages control collection, you would need to iterate over the controls, or use findcontrol on its container to get to it.


A better solution would be to add a literal control either inside the h2 tag, or in place of the h2 tag and have the master page output the h2 when the page is loaded.  You could then add a public property to the masterpage to allow the Page to set either a string member that you will assign to the literal control or access the literal control directly.


Note, you will need to either cast the masterpage back to its type or add the masterpage directive to the page.


Happy to provide samples if you need it.


Regards


Si

Hi,

Give and Id and Put RunatServer tag and then use "Findcontrol"

http://msdn.microsoft.com/en-us/library/486wc64h.aspx

and Added to HtmlGeneric Control..

http://msdn.microsoft.com/en-us/library/7512d0d0%28v=VS.100%29.aspx

make your H2 a runat="server" by using

<asp:Literal id="h2Control" text ="<h2>Hello World</h2>"

control, and then, try Master.FindControl("h2Control") to find it from the content page

and this is the ContentPage's code behind:

}




so, 

if 2 , then see what type it is

Hi,


Try this.


In your master page .master file



<h2>
<asp:literal runat="server" id="uxMyPageTitle" mode="Transform" />
</h2>

In your Master page code file (not this is c#, you will need to convert it if you use VB


public string PageTitle
{
   get {
          return uxMyPageTitle.Text;
   }
   set {
         uxMyPageTitle.Text = value;
   }
}


So in your content page, you can do the following:

 protected void Page_Load(object sender, EventArgs e)
    {
          ((YourMasterPageClassHere)Master).PageTitle = "My Page Title";
}


Regards


Si

I chenged the code as bellow:

HtmlGenericControl h2 = (HtmlGenericControl)Master.FindControl("MyPageTitle");
h2.InnerText = "Forums";

But h2 is null.

if your "H2" control is inside other controls then you are likely to get this error, so, first give SlickSim's approach a shot , or do a FindControl("ParentControl").FindControl("child") in debug untill u reach the H2.