Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Attributes.Add not working in composite control

Posted on 2008-09-30
5
Medium Priority
?
537 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 60

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 60

Accepted Solution

by:
Kevin Cross earned 1500 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 60

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

718 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