|
I have a page, Default.aspx, and a UserControl, HelloControl.ascx. In the page, I dynamically instantiate the control as follows:
protected void Page_Load(object sender, EventArgs e)
{
HelloControl c = new HelloControl();
Response.Write(c.Greet());
}
This works fine, and the user control returns "Hello from a control", which is written to the response. I have no @Register directive in Default.aspx, but when I try a similar dynamic control creation on a client's machine, I get an error that the "Type or Namespace does not exist".
I have even gotten feedback, on forums, from MS, that I need the @Register directive, but I obviously don't. Can anyone help me out with info on how and when the user control is compiled if no @Register directive references it?
|
|
|
|
|
u have to register the usercontrol on htmlview like this on top
<@>
and then call it where u want like this:
<uc1:scmheader id="SCMHeader1" runat="server" xmlns:uc1="#unknown">
|
|
|
|
|
devesh sinha wrote: and then call it where u want like this:
<uc1:scmheader id="SCMHeader1" runat="server" xmlns:uc1="#unknown">
And how would I do that in pure C#?
|
|
|
|
|
It is nice to see you trying to help. But, you need to understand what the problem is before giving your advice.
How is your solution going to help the OP?
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
@Register directive is needed for aspx pages not the code behind. You did not add the user control tag to your aspx, thus the only way to add it. either
1. as you have shown, writing to the response stream your self
2. add it to the Control collection Page.Controls.Add()
The user control gets compiled by JIT. To verify this, introduce syntax error in your HelloControl code. You will notice that at run time you will get a syntax error.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Yusuf.A wrote: The user control gets compiled by JIT. To verify this, introduce syntax error in your HelloControl code. You will notice that at run time you will get a syntax error.
I just did, and it still works, indicating that the user control is, for some reason, not being re-compiled. This is close to my client scenario, where the control seems to not get compiled at all.
|
|
|
|
|
Brady Kelly wrote: I just did, and it still works,
Either you have something cached, or referencing wrong assembly.
Here is what have done to verify.
1. Created new web application - Used default.aspx
2. Added User Control, following your example I have
public string Greeting()
{
return ("Hello From User Control");
}
3. call User Control from default page
protected void Page_Load(object sender, EventArgs e)
{
WebUserControl uc = new WebUserControl();
Response.Write(uc.Greeting());
}
Run the app and I get Hello From User Control
Now while the app is running on my browser I changed my method to
public string Greeting()
{
int i =
return ("Hello From User Control");
}
notice I left ';' intentionally and saved the code. I hit refresh on the page which is already running, JIT kicks in and throws an error.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Thanks. This is very odd: I followed your steps to repro, and I get exactly the expected error, but even when I change my original web site to exactly the same error code as yours, I still get "Hello from a control"! This even after clearing the cache on FF.
My one site is stuck on a working user control, and the other is responding immediately to changes to the user control code. At least now I'm able to reproduce the error that the client gets!
|
|
|
|
|
The way the ASP.NET compilation works is pretty complex. In general it is not possible to use control/page references across web pages unless you are using @Reference[^].
The reason why referencing UserControl works sometimes and not some other times is because it is up to the discretion of ASP.NET build provider to build the control and page in the same assembly or in different assemblies. When they are in the same assembly things will work and when they are in different assemblies things will not. For pages the assembly names are generally of the form App_Web.If the compilation is in one go everything will be in the same assembly but on the client site probably the web site was already compiled and you added the user control later on. In any case it is better not to expect that user controls and assemblies will be in the same assembly.
There are 2 ways to solve this issue:
1. Declare an interface and put that interface in App_Code directory. The App_Code directory is referenced by all pages/controls automatically. Make the user control implement this interface. In the page access this interface.
2. Move to Web Application projects. The web application project compiles the cs code into a single assembly and you can reference controls from the pages and so on.
|
|
|
|
|
Thanks Rama. Option 1 seems to qualify, but my misfortune of not being able to recreate the error prevents me checking if I can do this. Option 2 is not an option at this point.
I'll look at using @Reference, this looks like it might 'coerce' the damn build provider to work properly. Is there any way I can delete all previous compilations on the client machine?
|
|
|
|
|
Brady Kelly wrote: Is there any way I can delete all previous compilations on the client machine?
There are two options again:
1. In the web.config file set the following setting:
<compilation debug="true" strict="false" explicit="true" tempDirectory="f:\development\temp\asp.net">
where tempDirectory is a directory of you choice. You can actually see the assemblies being built in a subfolder within that directory. Of course you can delete it whenever you want to.
2. The default location of compilation folder is "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files". You will find a sub directory with the name of the web site root in that directory. You can delete files from that directory (you may need the web server to be shutdown)
|
|
|
|
|
When you deploy your website, do you provide a pre-compiled dll, or are you compiling dynamically in production?
|
|
|
|
|
Dynamically in production.
|
|
|
|
|
Don't know if this is any help at all, but..
We've encountered problems before where we had number of user controls, in different folders, where one control referenced another in a different folder (not really ideal...).
As the website compiles, it seems to work down through the directories, creating a dll for each, so, in some cases, we found that we got compilation errors when one control goes looking for another, but it has not been compiled yet.
|
|
|
|
|
Hi
I have two div in my web page and two radio button
I want initially both div will be invisible.When i am selecting one radio button i want one div will be visible and other will be invisible
I am using IE-7
please help me
|
|
|
|
|
u can use javascrpit function for this like:
function showdiv1()
{
document.getElementById('div1').style.display='block'; // to display
document.getElementById('div2').style.display='none'; // to hide
}
and make similar function for div2 and call them on selection of radiobutton.
|
|
|
|
|
I tried it but it is not working
|
|
|
|
|
try the ajax accordian pane thats the real fast way to do it in asp and also you can find it on google or codeplex for this third party dll and the functions working can be seen on asp.net/samples.If you want more then these are deeply described in wrox asp.net prof. buy the book.
byee,
cheers
|
|
|
|
|
set display:none of ur div where u have defiend ur div so that intially it is not visible.
There is nothing like which woultd not work try it and tell me exatcly what problem is coming.
|
|
|
|
|
You can do it just using JavaScript. Download jQuery 1.3.2[^] and test the code below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br />
<html><br />
<head><br />
<title>DIV show / hide example</title><br />
<script type="text/javascript" src="jquery-1.3.2.min.js"></script><br />
<script type="text/javascript"><br />
$(document).ready(function() {<br />
$('#box_dv div').each(function() {<br />
$(this).hide();<br />
});<br />
$('#box_rdo input:radio').each(function() {<br />
$(this).click(function() {<br />
$('#box_dv div').hide();<br />
$('#' + $(this).attr('value')).show();<br />
});<br />
})<br />
});<br />
</script><br />
</head><br />
<body><br />
<div><br />
<div id="box_rdo"><br />
<input type="radio" id="r1" name="rdo" value="d1" /><label for="r1">DIV 1</label><br />
<input type="radio" id="r2" name="rdo" value="d2" /><label for="r2">DIV 2</label><br />
</div><br />
<br /><br />
<div id="box_dv"><br />
<div id="d1"><br />
<h1>DIV 1</h1><br />
This is the DIV 1 content!<br />
</div><br />
<br />
<div id="d2"><br />
<h1>DIV 2</h1><br />
This is the DIV 2 content!<br />
</div><br />
</div><br />
</div><br />
</body><br />
</html>
If you gonna use asp.net server controls, instead of <input type="radio"> and <div> use <asp:RadioButtonList> and <asp:Panel>... Handle the OnSelectedIndexChanged event of the radio button list to manipulate the visibility of the asp:panel's (div's).
modified on Monday, April 6, 2009 12:47 PM
|
|
|
|
|
The sample javascript is below.
function showdiv()
{
//To hide div
document.getElementById("DIV").style.display='none';
//To show div
document.getElementById("DIV").style.display='block';
}
....
....
....
....
.....
Use this in your code as per your requirement and this should definitely help you out.
|
|
|
|
|
Make both the divs runat='server' and assign them some ID
and write your code according to that.
e.g. on Page_Load if u want to both the divs invisible then :
div1.Visible= false;
div2.Visible= false;
Similarly you can write code according to the radio button selection.
Happy Coding,
Vivek Rathore
|
|
|
|
|
Hi,
Please help me with your ideas for the following
1.Does .net support for WEBDAV protocol?
2.Can I implement .net remoting using WEBDAV protocol?
Right now I implemented .net remoting using TCP/IP protocol.It is working fine.I need to change this to support the WEBDAV protocol.
Please help me.
|
|
|
|
|
Don't crosspost. See the answers in the C# forum...
|
|
|
|
|
Hi,
Public MasterDispDt As String
Public Sub ExFunction()
MasterDispDt = DtlsDs.Tables("DtlsTab").Rows(r).Item("DispDate").ToString
End Sub
TxtDispDate is a Textbox, Calender Selected value assigned to it.
Dim TDate As Date = CDate(Trim(txtDespDate.Text))
Dim MDate As Date = CDate(Trim(MasterDispDt))
If TDate < MDate Then
'Some Code
Endif
TxtDispDate I selected as '28-04-2009'
The above Code giving Error :
Error : Conversion from string "28-04-2009" to type 'Date' is not valid.
Pl. Help me out
Ramesh Sambari
|
|
|
|