2

Registration of my user control on .aspx page like this:

<uc:MyControl Id="MyControlId" runat="server"></uc:MyControl>

And I'm using a method that belongs to this user control on code behind of .aspx page:

MyControlId.MyMethod();

But I get this error while parsing: "Cannot create an object of type 'System.Guid' from its string representation 'MyControlId' for the 'Id' property". How can I fix this?

Note: This is not the solution I'm looking for: Cannot create an object of type 'System.Object' from its string representation

MyMethod() in user control:

public void MyMethod()
{
  BindInfo();
  InfoArea.Style.Add("display", "block");
}
4
  • Your starting tag is uc:MyControl while your ending tag is /uc:GeneralInfo does it even compile? Commented Oct 20, 2014 at 11:59
  • Sorry for that. I changed the original code part while asking, just missed out. There is no compilation problem. Thanks for reminding me. Commented Oct 20, 2014 at 12:03
  • Can you show the code of your MyControl class? Commented Oct 20, 2014 at 12:08
  • I added the code of MyMethod(). Commented Oct 20, 2014 at 12:26

2 Answers 2

2

I've found the real solution. There was a Guid property named as 'Id' in the interface of my user control. So, the interface member 'Id' conflicts with the Id attribute of the user control. Changing the interface member's name solved the problem.

Sign up to request clarification or add additional context in comments.

Comments

1

Replace the below

MyControlId.MyMethod();

with

MyControl.MyMethod();

6 Comments

I couldn't access the control using tagname.
you can not call the MyMethod by using the id of the user control instead you should use the same user control class name
@zarathustra import the namespace in your code behind of the userControl
@zarathustra I don't think that is true. <uc:MyControl Id="MyControlId" ..></uc:MyControl> results in a (generated) field of type MyControl with name MyControlId. So, yes, you do refer to the usercontrol instance as specified by the Id tag. If you use the control class name, you are not referring to an instance method, but to a static method.
Thanks for replies. Using the name of control solved the problem.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.