views:

118

answers:

0

Hi guys!

Not using forms!!

Scenario: 1. 3 divs - div 1 and 2 display: block, div 3 display: none;

  1. User clicks on Edit - div1 and 2 display: none, div 3 display: block

  2. In div 3 i list all the articles the user has written (repeater).

  3. While repeater items are created i also create in hidden placeholder divs with textbox:header, textbox:mainbody input and submit button.

  4. If user clicks on one of the listed items, fancybox opens and shows

Header: [ name of the header for that article]

MainBody: [ the body of the article ]

[Button Save]

Issue: The Save Button is connected to code behind and what it does is that it takes the changed text and saves over the old text in the DataBase.

For some reason, while clicking, the button Nothing happens.

Sumery: I am in the fancy box. I do see the header and mainbody textbox full with data loaded from database. I alter the data and i click on the save button but nothing happens.

    <div id="Section3">

    <asp:Repeater ID="rptOverview" runat="server" OnItemDataBound="rptOverview_OnItemDataBound" OnDataBinding="ClearBindning" >

        <ItemTemplate>
            <li >                    
                <a ID="rptLink" runat="server" class="myDummyClass">  </a>                    
            </li>
        </ItemTemplate>       
    </asp:Repeater>                  

    <div style="display:none;">
    <asp:PlaceHolder id="DivPlaceHolder" runat="server">
    </asp:PlaceHolder>    
    </div>

------Code Behind------

   protected void rptOverview_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
       if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
       {
           link = (PageData) e.Item.DataItem;
           var aLink = (HtmlAnchor)e.Item.FindControl("rptLink");

           var newDiv = new HtmlGenericControl("div");               
           newDiv.ID = link.PageLink.ToString();
           newDiv.Style.Add("display", "block");
           newDiv.Style.Add("width", "500px");
           newDiv.Style.Add("height", "400px");

           var pTag = new HtmlGenericControl("p");
           pTag.Style.Add("margin-bottom", "1px");

           var txtHeader = new Literal();
           txtHeader.Text = "Rubrik:";

           pTag.Controls.Add(txtHeader);

           var newInputHeader = new TextBox();
           newInputHeader.ID = link.PageLink.ToString();
           newInputHeader.Text = link.PageName != null ? link.PageName : string.Empty;
           newInputHeader.Style.Add("width", "98%");

           var newInputMainBody = new TextBox();
           newInputMainBody.ID = link.PageLink.ToString();
           newInputMainBody.TextMode = TextBoxMode.MultiLine;
           newInputMainBody.Text = link["MainBody"] != null ? link["MainBody"] as string : string.Empty;
           newInputMainBody.Rows = 25;
           newInputMainBody.Style.Add("width", "98%");

           var newCloseBtn = new HtmlAnchor();
           newCloseBtn.CausesValidation = false;
           newCloseBtn.HRef = "#";
           newCloseBtn.Attributes.Add("onclick", "$.fancybox.close();");
           newCloseBtn.InnerText = "close";

           var saveBtn = new Button();
           saveBtn.CausesValidation = false;
           saveBtn.CommandName = rptOverview.Parent.ClientID + "_" + newInputHeader.ID + "," + rptOverview.Parent.ClientID + "_" + newInputMainBody.ID;
           saveBtn.CommandArgument = rptOverview.Parent.ClientID + "_" + newDiv.ID;
           saveBtn.Text = "save";
           saveBtn.Command += new CommandEventHandler(OnClick);                              

           newDiv.Controls.Add(pTag);
           newDiv.Controls.Add(newInputHeader);
           newDiv.Controls.Add(newInputMainBody); 
           newDiv.Controls.Add(newCloseBtn);
           newDiv.Controls.Add(saveBtn);

           aLink.Title = link.PageName;
           aLink.HRef = "#" + rptOverview.Parent.ClientID + "_" + newDiv.ID;
           aLink.InnerText = link.PageName;
           aLink.CausesValidation = false;        

           DivPlaceHolder.Controls.Add(newDiv);                                             

       }
    }


    protected void OnClick(object sender, CommandEventArgs e)
    {
        string[] commandArgs = e.CommandName.ToString().Split(new char[] {','});
        string idHead = commandArgs[0];
        string idBody = commandArgs[1];

        TextBox n = (TextBox) this.Page.FindControl(idHead);
        TextBox m = (TextBox) this.Page.FindControl(idBody);

        Response.Write(n.Text +" "+m.Text );


    }

    protected void ClearBindning(object sender, EventArgs e)
    {
        DivPlaceHolder.Controls.Clear();
    }

Any suggestion on how to make the Save button work?