Solved

Attributes.Add not working in composite control

Posted on 2008-09-30
5
472 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

9 Experts available now in Live!

Get 1:1 Help Now