Dotnetsharepointwatever’s Blog

Just another WordPress.com weblog

Archive for the ‘Uncategorized’ Category

MasterPage: Getting Dynamic Control ClientID

Posted by dotnetsharepointwatever on October 23, 2008

Accessing control from javascript could be quite trouble some when you are using MasterPage.
if you are having a TextBox in your page, the ClientID of the control will automatically generated as ctl00_ContentPlaceHolder1_TextBox1.
To make it easier, you can just simply hardcode the “ctl00_ContentPlaceHolder1_”

But, In my case hardcoding the “ctl00_ContentPlaceHolder1_” it’s not a good idea, Because the MasterPage could be Recursive, and the Page could use by many project ( using embedded resource and so-on). It will generated different ClientID when it’s being call by different Project.

here’s something you can do, to get the ClientID :

      function showTextBoxClientId ()

      {

            var txtBox = ‘<%=TextBox1.ClientID%>’;

            alert (txtBox);

      }

 

But, what if the control is generated dynamically??, something like this..

        private void GenerateControl()
        {
            Panel panel = new Panel();
            panel.ID = “GeneratedPanel1″;
            panel.Controls.Add(new LiteralControl(“CLick button to hide / show this text “));
            Button btn = new Button();
            btn.ID = “TestBtn”;
            btn.Text = “Hide/Show”;
            btn.Attributes.Add(“onClick”, “return ShowHidePanel (‘” + panel.ClientID + “‘);”);
            Panel1.Controls.Add(btn);
            Panel1.Controls.Add(panel);
        }

 
The showHidePanel alert will only show “GeneratedPanel1″, without “ctl00_ContentPlaceHolder1_”

function ShowHidePanel(id) {

{

alert (id);

return false;

}

 

Then, here’s what I did in order to get it right..

function ShowHidePanel(id) {

var tempid = ”;

tempid = tempid.replace(‘TextBox1′, id);

obj = document.getElementById(tempid);

 

if (obj.style.display == ‘none’)

{ obj.style.display = ”; }

else

{ obj.style.display = ‘none’; }

 

return false;

}

I get the “ctl00_ContentPlaceHolder1_” from non dynamic control, and just replace the controlID with the control that we need.

Please download the whole code here

Posted in Uncategorized | Tagged: , , , , , | Leave a Comment »

How to Fix: You do not have permission to open this file on Excel Services

Posted by dotnetsharepointwatever on October 23, 2008

I just started learning excel services in MOSS 2007. I am using the this book with the code companion.
When I was trying the first hello world code example, I hit error
“You do not have permission to open this file on Excel Services ” at this code below

I just started learning excel services in MOSS 2007. I am using the this book with the code companion.
When I was trying the first hello world code example, I hit error
“You do not have permission to open this file on Excel Services ” at this code below

after spent about 2 hours google-ing, and try this and there, I managed to solve this..
All my setting are correct, I only missed this one part

When creating trusted file, For this programming excel services.. you have to select HTTP as the location type

then, it’s working well !!

but, let say it’s not your problem, please check this following link for other setting..
http://sharenotes.wordpress.com/2007/12/21/excel-services-charts-spreadsheets-worksheets-in-sharepoint-issues/

Hope it’s work for you :)

Posted in Uncategorized | Leave a Comment »

Sharepoint: Developing User Control with Code Behind

Posted by dotnetsharepointwatever on October 23, 2008

it’s kind of easy and simple actually..
1. you just need to copy the ascx to the 12 hive folder..
2. register the dll as global assembly,
3. since sharepoint accessing all dll, from gac, we need to change the top part of the ascx file


I am not going to waste time to make a long blog about this.. cause the following blog did a great job, check it out here :
http://jamestsai.net/Blog/post/Using-ASPNET-Web-User-Control-with-Code-Behind-in-SharePoint.aspx

Posted in Uncategorized | Leave a Comment »

Dynamically/Run Time Create Control and access the Entered value

Posted by dotnetsharepointwatever on October 23, 2008

There will be a time when you need to create a control (textbox/dropdownlist/label) dynamically.

Then what you need to do is.
1. Add a panel into your form
2. Create code behind that generate the control, and put it into the panel.
3. CALL THE CONTROL GENERATE PART EVERY POST BACK


You need to generate the control every page post back, otherwise the control wont be there after post back.
But don’t worry about the value of the control, it will wont disappear, it will still be there, it’s being store in the viewstate.     

Since code speaks thousand words, Please take a look at the code below :
- Default.aspx.cs

 

        protected void Page_Init(object sender, EventArgs e)

        {

            GenerateControl();

        }

        private void GenerateControl()

        {

            Panel1.Controls.Clear ();

            Table tbl = new Table();

            tbl.ID = “table123″;

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

            {

                TableRow tr = new TableRow();

 

                // creating label 

                TableCell tc = new TableCell();

                Label lbl = new Label();

                lbl.Text = “Value ” + (i+1).ToString();

                tc.Controls.Add(lbl);

                tr.Cells.Add(tc);

 

                tc = new TableCell();

                lbl = new Label();

                lbl.Text = “:”;

                tc.Controls.Add(lbl);

                tr.Cells.Add(tc);

 

                // creating txtbox  

                tc = new TableCell();

                TextBox txt = new TextBox();

                txt.ID = “DynamicTextBox” + i.ToString();

                tc.Controls.Add(txt);

                tr.Cells.Add(tc);

 

                tbl.Rows.Add(tr);

            }

            Panel1.Controls.Add(tbl);

 

        }

 

        protected void BtnGetValue_Click(object sender, EventArgs e)

        {            

            string Value = string.Empty;

            Table tbl = (Table)Panel1.FindControl(“table123″);

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

            {

                TextBox txt = (TextBox ) tbl.FindControl(“DynamicTextBox” + i.ToString());

                Value = Value + txt.Text + ” “;

            }

            Label1.Text = Value;

        } 

 

        protected void BtnGenerateControl_Click(object sender, EventArgs e)

        {

            NumberOfControl = Int32.Parse(DropDownList1.SelectedValue);

            GenerateControl();

        }

    }

}

 

or, download the whole solution code here

Posted in Uncategorized | Tagged: , , , | Leave a Comment »