Solved

Attributes.Add not working in composite control

Posted on 2008-09-30
5
483 Views
Last Modified: 2013-12-17
I have a ton of composite controls and i have the Attributes.Add function on a lot of my asp controls inside of them. I noticed something. If i go directly to the page via the menu or typing a url, the attributes are added flawlessly. If i do a response.redirect or server.transfer, these attributes dont get added. If i hit f5 then the attributes appear. What is the problem? Heres the piece of code where im adding the attribute:

  protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            addBtn.Click += new EventHandler(addBtn_Click);
            addBtn.Text = "Add Leg";
            //addBtn.OnClientClick = "MyFunc();"; <--this doesnt work either
            addBtn.Attributes.Add("onclick", "MyFunc();");
}
0
Comment
Question by:troycomp
  • 3
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22610261
You are using the OnInit which may not be getting called when you use the other methods since the page may already be initialized at that point.  Try moving this code to your page load sub.
0
 

Author Comment

by:troycomp
ID: 22610335
It is getting called. I put a breakpoint on the line in question and it stoped. I also moved it to the CreateChildControls() method and still a no go. This has to do with the difference between response.redirect (or server.transfer) and accessing the page directly. Thats the only difference in what im doing.
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 22610448
If it were differences in Server.Transfer and Response.Redirect may have been differences in how page transfer, but not sure why then for your case where both don't work if moving the code to Page_Load didn't fix the issue.
0
 

Author Comment

by:troycomp
ID: 22610556
I added it to page_load on the aspx page and it works now. I misunderstood you earlier.  Honestly im doing this for another one of my controls. Ive worked almost 30 hours in 2 days so my brain is tired. Thanks

0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22610571
Not a problem at all.

Glad I re-iterated it.  I was actually just trying to let you and other experts know I was out of ideas beyond the Page_Load so you would get the help you needed. :)

Anyway, good luck with remainder of the project.

Regards,
Kevin
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now