Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Wednesday, March 28, 2012

Very weird error. Ajax controls call default.aspx

I have a few pages in my site... and for some reason, if there's any ajax controls on the page, it calls default.aspx and runs the code every time any aspx page with an ajax control exists on it. Problem is, default.aspx resets my session variables.

Why does Ajax call the default.aspx page code? It only runs the CS file... it doesn't actually show the default.aspx page.

I doubt it calls it. Do you have a component in your site somewhere that's got a url of "/" attached to it somewhere, and that's invoking the default page?


it only seemed to only happen when I have Certain Ajax controls on the page. Note, it only does it with Internet Explorer 6 and 7. Firefox seems to be fine.

For example, I have a collapsible PAnel in each row of a Gridview. That is in an UpdatePanel. When the Gridview is populated (and I have a breakpoint on the default.aspx.cs file), it goes through that code. Well, I set my session variables on that page, so in essence it resets them.

It seems like it does this AFTER the page is loaded, because the labels that show content based on those session variables aren't updated until I go to a new page.

It only does this when I have a collapsible panel in IE. The panel is set to collapsed.


Actually, it appears that AJAX is clearing the Session Variables. I don't know where it's doing this, though.

Monday, March 26, 2012

Visible attribute on Atlas controls

Hi,

This small piece of code doesn't work in the current Atlas CTP:

<div>

<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="True">

</atlas:ScriptManager>

</div>

<atlas:UpdateProgressID="UpdateProgress1"runat="server"Visible="false">

<ProgressTemplate>

Contacting server...

<br/>

<br/>

<inputid="abortButton"runat="server"type="button"value="Abort Request"/>

</ProgressTemplate>

</atlas:UpdateProgress>

The controls that implement the IScriptObject (UpdateProgress,…) use to override the RenderScript method in order to write xml/script output. The problem arrives when visible="false" for this control; then the control itself doesn't render, but it does the xml/script, what provokes a javascript error. This behavior is by design? Am I correct? Then, how could I override this behavior (and avoid this problem)? One solution could be to unregister the control in the script manager, but there is no ScriptManager.UnregisterControl (control).

Thanks

Fran

Anybody there??

style="display:none;"


Type 'Microsoft.Web.UI.UpdateProgress' does not have a public property named 'Style'

I think it would be great to have a nice Style or CssClass property, but there is nothing like that at the moment.

but that gave me another idea: a div surrounding the updateprogress, and apply the style to the div. it is not really a nice solution, but it works.

thanks

Fran

Visual verification extender

Hi,

Are there any plans for a visual verification extender that would be linked to a textbox control and that would show an obscured code that has to be entered by the user to protect against automated registrations?

Would be a nice control for the toolkit.

Thanks,

Jason

As far as I know there is currently no one working on a CAPTCHA extender, but we do have the NoBot extender which is designed to prevent many cases of automated posting that a turing test like CAPTCHA is supposed to block. Take a look athttp://ajax.asp.net/ajaxtoolkit/NoBot/NoBot.aspx

Cool...that should do the trick. Thanks.

Void System.Web.UI.ScriptManager.RegisterHiddenField(System.Web.UI.Page, System.String, Sy

It code worked fine on my PC..but gettting following message on server...

'Void System.Web.UI.ScriptManager.RegisterHiddenField(System.Web.UI.Page, System.String, System.String)'

i checked this threadhttp://forums.asp.net/p/1123792/1869084.aspx#1869084

but it doesn't help me...

Updating global assembly cache of server, solved this error

Some how installation is not updating GAC..so you have to do it manually


Hi,

I have the exact same problem. Can you please tell me how you were able to clear out the GAC and update it with the latest DLL? Just like you everything works on my PC but when it gets published to servers i get that same error.

Thanks,
Kam


just copy the following DLL's fromC:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025 and paste it in folderc:\windows\assembly on server

System.Web.Extensions

System.Web.Extensions.Design

Hope it solves your problem, if not let me know


Hi,

Yup that fixed it perfectly. Thanks so much for the quick and accurate reply.

Kam

Want to call a javascript function from code behind

Hi.

I am trying to call a javascript function on button click, buttton is present in update panel. It is not working.

On button click event handler i m writing the following code

Response.Write("<script>functionname();</script>");

I have added script reference in script manager and given the path.

Response.Write("<script>functionname();</script>") --> this works if button is outside update panel.

Help me...

Why not try placing your javascript function name in the button's OnClientClick parameter? That way it calls it directly without requiring a post back...

OnClientClick = "functionname();"


PhunkNugget:

If you do that, which runs first, the javascript in the client or the

click event code in the code behind? may be related, so it's

important to know..I also need to invoke a modal popup

extender from code in a codebehind, not from a click event..

I'm watching this thread closely.. Geeked

Thanks in advance..


The OnClientClick runs first.


Kanwar,

You can't use Response.Write() inside an update panel. It conflicts with the ajax somehow (very annoying). You can attach the script to your button's onclick event in page load such as the following:

string myString="<script language='Javascript'>\n";

myString+="function fuctionname()\n";

myString+="{\n";

myString+="whatever your function does...\n";

myString+=

"}\n";myString+="</script>\n";

Page.RegisterClientScriptBlock(

"MYFUNCTION", myString);

btnMyButton.Attributes.Add(

"onClick","functionname();");

Then when you click on the MyButton, the javascript function will be called.

Saturday, March 24, 2012

Watermark and Popup Calendar issue

David, I download the lastest toolkit, and try the following code in aspx page. It is OK. But when I put it into a user control. It won't work!

The error is caused by code when clicked on popup calender:
var mydate = $("TextBox1").mydate;
The error message is Object is required

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" CodeFile="test2.aspx.vb" Inherits="test2" %>
<%@dotnet.itags.org. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
<div>
<script type="text/javascript" language="javascript">
function commitScript1() {

var mydate = $("TextBox1").mydate;
if("" == mydate) {
mydate = "";
}
$object("TextBoxWatermarkBehavior_TextBox1").set_Text(mydate);
}
</script>
<asp:TextBox ID="TextBox1" runat="server" Width="150"></asp:TextBox>
<asp:Panel ID="Panel4" runat="server" CssClass="popupControl">
<atlas:UpdatePanel ID="UpdatePanel6" runat="server" Mode="Conditional" RenderMode="Block">
<ContentTemplate>
<center>
<asp:Calendar ID="Calendar3" runat="server" BackColor="White" BorderColor="#999999"
CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="Black" Width="160px" OnSelectionChanged="Calendar3_SelectionChanged">
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<SelectorStyle BackColor="#CCCCCC" />
<WeekendDayStyle BackColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#808080" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
</asp:Calendar>
</center>
</ContentTemplate>
</atlas:UpdatePanel>
</asp:Panel>
<atlasToolkit:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender3" runat="server">
<atlasToolkit:TextBoxWatermarkProperties TargetControlID="TextBox1" WatermarkCssClass="watermarked"
WatermarkText="<DD/MM/YYYY>" ID="TextBoxWatermarkBehavior" />
</atlasToolkit:TextBoxWatermarkExtender>
<atlasToolkit:PopupControlExtender ID="PopupControlExtender3" runat="server">
<atlasToolkit:PopupControlProperties TargetControlID="TextBox1" PopupControlID="Panel4"
Position="Bottom" ID="PopControlBehavior1" CommitProperty="mydate" CommitScript="commitScript1()" />
</atlasToolkit:PopupControlExtender> </div>
</form>
</body>
</html
CodeFile:
Partial Class test2
Inherits System.Web.UI.Page
Protected Sub Calendar3_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
PopupControlExtender3.Commit(Calendar3.SelectedDate.ToShortDateString())
Calendar3.SelectedDate = Nothing
End Sub
End ClassI believe this thread addresses the issue you're seeing (hard-coded ID changed by inclusion in a different naming container):http://forums.asp.net/thread/1368445.aspx

WaterMark and CodeBehind

Is it possible to create a watermark control programmatically in code behind? If so can some one provide me with an example?

Thanks,

Kris

Hi Kris,

I think you should check out the first part ofFAQ Item #13.

Thanks,
Ted

Watermark and Atlas Client Side Code issue

If I connect a textbox to a watermark control and write client side code like
obj = new Sys.UI.TextBox($('<%=textbox1.ClientID%>'));

it will report Assertion Failed error even if I set ID property for watermark control.

Myabe it is a bug of Atlas.

You're missing a getElementByID. The following works for me:

function foo() {
obj = new Sys.UI.TextBox(document.getElementById('<%= TextBox1.ClientID %>'));
alert(obj);
}
foo();


Hi David, Thanks for your help.
After changing
obj = new Sys.UI.TextBox('<%= TextBox1.ClientID %>');
to
obj = new Sys.UI.TextBox(document.getElementById('<%= TextBox1.ClientID %>'));

I still get same Assertion Failed error.

With my case, this textbox1 is inside an UpdatePanel. In this Updatepanel, I have a button with some ASP.NET code. when Clicking on this button, it only cause partial rendering.

The javascript here only get a string from a popup window. After the code
obj = new Sys.UI.TextBox('<%= TextBox1.ClientID %>');
is executed, and then click on the button inside the Updatepanel, the error came out.

But if code
obj = new Sys.UI.TextBox('<%= TextBox1.ClientID %>');
never executed, everything is OK.

I think the issue here is that the wrapper for hte textbox has already been created, that's why you're getting the assert (for future issues, please paste in the test of the assertion as well, it's usually helpful).

try this code instead:

obj = $object('<%= TextBox1.ClientID %>');


Is there any way to disable the Watermark? I'm getting an assertion error following a postback when I've set the Watermark's target textbox's visible property to false. The error message is:

Assertion Failed: Could not find an HTML element with ID "ctl00_CH_NewFeedTextBox" for control of type "Sys.UI.TextBox".

My code is just a click handler that is setting the visible property of the textbox to false. I'd be happy to set the Enabled property of the Watermark to false as well... if it had such a property.


When you set the Visible property to false, the control isn't rendered at all to the client. Thus, there is no ctl00_CH_NewFeedTextBox control in your client-side page. try NewFeedTextVox.style.display="none" to hide it. This will make it render to the page, but not be visible in the browser.
Hi sburke_msft, If I change the code to
obj = $object('<%= TextBox1.ClientID %>');
then it will report error obj is null.

Here question is I want to use Atlas code and make things simply. If I do not use Atlas code here, just use javascript directly, no this problem.
It means watermark combine orginal javascript, no this problem.

I certainly *could* do that and get past this error, but the point is that the extenders are supposed to add functionality to other controls without requiring me to change how I'm using those controls. Since it is perfectly normal for developers to set the Visible property to false for TextBox controls (and since this is more efficient in terms of rendering time and bandwidth, etc.), the better solution would be to fix the Extender so that it can detect whether the Control it is associated with is Visible, and if not, disable itself. Or, barring that, expose an Enabled property that I can manually set to false when I disable/invisible the control it is targeting.


Agreed. However to be overly blunt, before a fix comes out, you have only ( as far as I know, correct me if wrong ) 2 options: write your own extender, or use the display property.

This has come up several times. As pointed out here, Visible=false means that the control isn't rendered, so there's no way the client side code can handle it.

We've talked about possible solutions, but none of them are automagic and still reasonable:

1) We could flip the visible bit and add display:none via the extender - this could expose security issues by rendering code that wasn't intended to be

2) We could throw an exception - this means you still need to make this change to your HTML

3) We could do nothing - this makes it pretty hard to debug and people waste time trying to figure out why X isn't working.

So at the end of the day, yes, you need to make a markup change here. Our goal with extenders is to allow you to do as much as possible without modifying the original page but there are many, many scenarios when this just simply isn't possible.

Hope that helps.


In my scenario, the request I would have is that the extender expose an Enabled property (or Visible, but since most of them aren't really visible to begin with, Enabled is more intuitive). If I *know* that I'm writing some code that is going to take the target of the extender away, then that gives me the developer to option of turning off the extender in that same chunk of code. Meanwhile, everything else works as before.

I know I'm going to have to write code for this situation to work out. That's ok - that's not my point. What I'm going for is the best implementation for the Extender controls.

The question is, would I rather

A) Write some CSS code to hide my textbox when I have years of experience, best practices, and thousands of lines of code showing me that to do this I set Visible to False.

or

B) Modify the control that I've just added to the page, the one that I'm already having to touch anyway, the one that is bombing out, and the one that has as one of its core advantages the lack of necessity to touch its target control.

My vote is B. The code for this should be simple -- wrap the control's inner workings in a big if(this.Enabled) statement.

Thanks - I hope that clearly makes my point/recommendation.


I guess my underlying question, which I'll make explicit here, is:

Whynot have an Enabled property on Extender controls to enable/disable their behavior?


Actually this has been solved - I forgot that we did make a change here. Make sure you have a new Toolkit build.

If the target control isn't Visible, we simply don't emit the hookup, so nothing happens. Once it becomes visible, we'll generate the hookup and it'll start working.

Wednesday, March 21, 2012

WCF Service Library

Can someone point me to links with sample code (preferably C#) where I can learn on developing WCF Service Library. I want to integrate my other projects that have my objects into the WCF Service Library project. Also I would like to know where I can learn more on best practices on how to develop .Net 3.5 applications using the service architecture and ajax.

Thanks

No one doing WCF?


Hi,

You can refer tothis documentto get start with WCF.