Showing posts with label updatepanel. Show all posts
Showing posts with label updatepanel. Show all posts

Wednesday, March 28, 2012

Why IsPostBack=false? How to repair that?

I'm using Ajax.Net. There is UpdatePanel on the page. It contains GridView. When I press "Edit", "Update" or "Cancel" button in the GridView then UpdatePanel reloads. Also executes code "if (!IsPostBack) { ... }" in Page_Load event on the server - but I don't need it!!! This code must run only once when page is loading for the first time.

protected void Page_Load(object sender, EventArgs e) {if (!IsPostBack) { ...// Here there are bindings for each control. // This code must run only once ...// On every action with GridView (which is placed in the UpdatePanel) // this code executes again and again. // Why? And how to prevent that? } }

1) Why IsPostBack=false (in Page_Load) on any action with GridView?

2) How to prevent that?

when you are clicking the button it's like you are reloading the all page but not the design... If you do not bind again the gridview loses data... Best solution is to cache the datatable that binds the gridview and binding the gridview to that... You can always verify the state of the grid to verify if you do some code...

As I understood, on every asynchronious postback (or mayme it's callback) the page is creating as it is not postback (isPostBack=false).

I think that it is better to use Session instead of Cache because every user has it's own data in the tabe.


cache in client... it's not postback... because the reference it's different... when you have difficulties test without the updatepanel to see if it's another reference of the page or not...

and i know what you're thinking the adress it's the same... it's ASP my friend... works that way.


What means "cache in client"? How? I can cache data only on server.


HttpContext.Current.Cache.Insert(itemString, Obj, HttpCacheability.Public, DateTime.Now.AddHours(expiration), TimeSpan.Zero)



Oh, it's caching on the server side, I thought you means caching data on the client side.

I change a bit my question. So, on each asynchronious postback executes code "if (!IsPostBack) { ... }" in Page_Load. But I want to prevent it. This code must executes only once when page is loading for the first time. How can I know if the page is loading for the first time or it is asynchronious postback? I want something like that: "if (!IsPostBack && !isAsynchroniousPostBack) { ... }"


did you tried with page.callback?


most likely no. what do you mean?


Put if not ispostback and not iscallback...


I wrote "!IsPostBack && !IsCallback && !IsAsync" - IsCallback and IsAsync always =false. IsPostBack in some cases =true and in some cases = false


tell me what are the cases that give true...

you don't have the need to put all of this...

if it doesn't control for you the postback you can put a viewstate that keeps the state of the grid.

just like this:

If not ispostback and viewstate("Should_Enter_Here")

end if

and in the event of the grid put this viewstate equals a true.


What you are looking for isIf (!ScriptManager.GetCurrent(Page).IsInAsyncPostBack).

http://www.asp.net/learn/ajax-videos/video-173.aspx


Thanks

why Javascript doesnt work properly in updatepanel?

i wanna my gridview to change into editrow model by click any space in the row , so i wrote in the aspx page:

.....
<script type="text/javascript">
function ClickEvent(cId)
{
var id=cId;
document.getElementById("rowid").value=id;
document.getElementById("btnBindData").click();
}
</script>
.....

<asp:LinkButton ID="btnBindData" runat="server" OnClick="btnBindData_Click" Width="0px" style="width:0px; height:0px"></asp:LinkButton>
<input type="hidden" id="rowid" runat="server" /> //send clicked row index to editindex property

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="userName" HeaderText="userName" SortExpression="userName" />
<asp:BoundField DataField="userPassword" HeaderText="userPassword" SortExpression="userPassword" />
</Columns>
</asp:GridView>

In the aspx.cs file i wrote:

.......

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#dfe345'");

e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

e.Row.Attributes["style"] = "Cursor:hand";

e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.RowIndex + "')");

}
}

......

protected void btnBindData_Click(object sender, EventArgs e)
{
GridView1.EditIndex=Convert.Int32(this.rowid.Value);

.....

GridView1.DataBind();
}

It works well without UpdatePanel ,but when put the GridView in the UpdatePanel ,when I click the row, the GridView got disappeared.

Replace asp:LinkButton with asp:Button. If you want you can sorround your button with a hidden div (to hide from the user). Also add UseSubmitBehavior="false" to the asp:Button.

For example:

<div style="display: none; line-height: 0pt;">
<asp:Button id="btnBindData" runat="server" OnClick="btnBindData_Click" UseSubmitBehavior="false" />
</div>

why page load is called when an updatepanel is updated

Hi,

i have just observed that when a request is posted to server inside an updatepanel. then load method of page is called.

create a page with script manager and updatepanel. put a button inside the panel. add a msgbox in the load eventhandler of page.

now when u will click the button page load eventhandler would be executed. i was expecting that only the load event of update panel would be executed not the page one. because what ajax says is that whole page is not reloaded only the updatepanel is reloaded. does it mean that the ajax only helps to not activate the back button on browser but underlying it reloads the page in fact.

thanks

Hi i think you misunderstood something. what AJAX meant for is not exactly for asynchronous postbacks. This means that you cant execute two threads parallelly. But what it does is partial rendering. During an async postback all the usual events will be executed but only the contents inside the Update panel will be rendered.


hello.

well, what they're trying to say is that only the updatepanel contents will be updated during a partial postback. you can use the scriptmanager isinasyncpostback property to see if you're in a partial postback scenario:

http://asp.net/AJAX/Documentation/Live/mref/P_System_Web_UI_ScriptManager_IsInAsyncPostBack.aspx


rex_alias:

Hi i think you misunderstood something. what AJAX meant for is not exactly for asynchronous postbacks. This means that you cant execute two threads parallelly. But what it does is partial rendering. During an async postback all the usual events will be executed but only the contents inside the Update panel will be rendered.

I'm pretty sure that's exactly what AJAX is meant for.

And you can execute two threads parallelly.

Partial rendering isn't related to AJAX, you can have partial rendering without AJAX, and you can have AJAX without partial rendering, although it's implemented in the UpdatePanel and its implementation uses AJAX.

And yes, the whole life cycle of the page happens on the server, but only the relevant portions of the output are rendered into a xml based diff-gram, and sent to the client.


This is the nature of Update Panel. You can filter out the Regular Post Back with an Async by Checking the Page ScriptManager.IsInAsyncPostBack. Or if you do not want to page to be called then use the Client Centric Development Model which is calling the Web Service or Static Page Methods.

Why Sys.WebForms.PageRequestManager only with UpdatePanel?

Why do I only get access to Sys.WebForms.PageRequestManager if I have an updatepanel in my page? I have some really good uses for this method, but right now I only get access to the object if I include an UpdatePanel in the page.

If I want to include this when I have my control in the page, what is the parameters needed to extract it from the resources using Page.ClientScript.GetWebResourceUrl ?

In the RTM version (due out by the end of this month), Sys.WebForms.PageRequestManager will be available even if you don't have an UpdatePanel on the page. In the mean time, I recommend just putting an empty one on the page: <asp:UpdatePanel runat="server" />.


Perfect !

Wow - glad I found this post, that was going to be a long, painful and probably fruitless debug session otherwise. Thanks for that!

PS. Anyone know *why* this is the case?

Why templating the content of the UpdatePanel?

Many ASP controls use template for their content (theGridView being a good example). TheUpdatePanel has aContentTemplate property that, as the name suggests, contains the content of the UpdatePanel.

Yet, since the UpdatePanel is not a repeater control, I do not grasp (as a consumer of the ATLAS library) the interest of templating the content of the UpdatePanel. Does some has an idea why a ContentTemplate is used instead of the regular control children?

Thanks in advance,
Joannès
http://www.peoplewords.com

hello.

i'd say that a template let's you have complete control over the content of the updatepanel. if you had a property of another type, you'd only be able to use elements of that type (or of a derived type)


ThePlaceHolder is not templated and but can include any element (as long as they inheritControl which is not a real constraint). My question can maybe be rephrased as "Why did the UpdatePanel not follow the PlaceHolder design pattern?".

Joannès

hum...how about designer integration? i'm not sure because i really don't use the designer, but can you drag-n-drop controls from the toolbox into a placeholder control?

Why this code does not work when its button is inside the AJAX “UpdatePanel” control ?

protectedvoid DownlFile_Click(object sender,EventArgs e)

{

string web_path ="./ items/part1.pdf";

string path = Server.MapPath(web_path);

FileStream MyFileStream =

newFileStream(path,FileMode.Open);

long FileSize;

FileSize = MyFileStream.Length;

byte[] Buffer =newbyte[(int)FileSize];

MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length);

MyFileStream.Close();

Response.ContentType ="application/pdf";

Response.AddHeader

("content-disposition","attachment; filename=part1.pdf");

Response.BinaryWrite(Buffer);

}

Hi paradise_wolf,

You can't use Response.Write in a AsyncPostback trigger event of an UpdatePanel. You need move the button outside the UpdatePanel or register it as Postback trigger.

Hope this helps,


Hispvlong

I am not sure if "RegisterAsyncPostBackControl" registers the button asPostback triggeras you suggested to do. I am getting this error message:

"Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.

Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Details: Error parsing near '%PDF-1.3%□□3389 0'."

Below is the relevant ASP.NET web form code and the added C# code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

protectedvoid Page_Load(object sender,EventArgs e)

{

ScriptManager1.RegisterAsyncPostBackControl(DownlFile);

..

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<asp:UpdatePanelID="ITEMS_LIST_EREADER_PANEL" runat="server"

UpdateMode="Conditional">

<ContentTemplate>

..

<asp:ButtonID="EreaderBtn"runat="server"Text="Next"

OnClick="EreaderBtn_Click"/>

..

</ContentTemplate>

</asp:UpdatePanel>

<asp:UpdatePanelID="DOWNLOAD_PANEL"UpdateMode="Conditional"

runat="server">

<ContentTemplate>

..

<tableID="DownloadDialogTb"visible="false"runat="server">

<tr>

<tdalign="center">

<asp:ButtonID="DownlFile"runat="server"Text="Download"

OnClick="DownlFile_Click"/>

</td>

</tr>

</table>

..

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlId="EreaderBtn"

EventName="Click"/>

</Triggers>

</asp:UpdatePanel>


Hi paradise_wolf,

You should use RegisterPostBackControl method to register a control as Postback trigger.

Hope this helps,


Thank you very much,spvlong . Big Smile

hi,

I am also getting same problem while generating PDF? i could not solver even after registring as postback trigger control. It gives me the same error.

If you have solved it, plz suggest the solution for the same.

thanks

Varsha


http://forums.asp.net/1662626/ShowThread.aspx#1662626

why Timer always reload updatepanel, is it right?

I tried to use timer to reload updatepanel, code like this

<atlas:TimerControl runat="server" ID="timer" Interval="5000"/>

<atlas:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
my controls...

</ContentTemplate>
</atlas:UpdatePanel>

right, I don't define trigger there. But even with code like that, the updatepanel still reload every 5 seconds, why it works this way?

thanks

I think I have found answer.

hello.

well, as you might have guesses by know, you have to set the mode property of the panel to conditional.

Why?

Why is it that the example below works just fine, but if I move the updatepanel anywhere else, it stops working? It won't work if I put it directly below the asp:Panel. It won't work if I put it inside the <table>... Is there some rule I should be following here for where an updatepanel should be placed?

<asp:Panel ID="pnlOptions2" runat="server"> <tr> <td valign="top"><strong>Additional Options</strong></td> <td colspan="2"> <asp:UpdatePanel ID="upOptions2" runat="Server"> <ContentTemplate> <table cellpadding="0" cellspacing="0" width="650"> <tr> <td width="175"><asp:CheckBox ID="cbTransparencies" runat="server" Checked="false" AutoPostBack="true" />Transparencies</td> <td width="125"><asp:CheckBox ID="cbLetter" runat="server" checked="false" AutoPostBack="true" />Letter</td> <td width="175"><asp:CheckBox ID="cb11x171" runat="server" checked="false" AutoPostBack="true" />11x17 1's</td> <td width="175"><asp:CheckBox ID="cbPaper" runat="Server" checked="false" AutoPostBack="true" />Provided Paper</td> </tr> <tr> <td><asp:CheckBox ID="cbNCR2" runat="Server" checked="false" AutoPostBack="true" />2 part NCR</td> <td><asp:CheckBox ID="cbLabels" runat="server" checked="false" AutoPostBack="true" />Labels</td> <td><asp:CheckBox ID="cb11x172" runat="server" checked="false" AutoPostBack="true" />11x17 2's</td> <td><asp:CheckBox ID="cbLaminate" runat="server" checked="false" AutoPostBack="true" />Laminate</td> </tr> <tr> <td><asp:CheckBox ID="cbNCR3" runat="Server" checked="false" AutoPostBack="true" />3 part NCR</td> <td><asp:CheckBox ID="cbTabs" runat="server" checked="false" AutoPostBack="true" />Tabs</td> <td><asp:CheckBox ID="cbCards" runat="server" checked="false" AutoPostBack="true" />Business Cards</td> </tr> <tr> <td><asp:CheckBox ID="cbNCR4" runat="Server" checked="false" AutoPostBack="true" />4 part NCR</td> <td><asp:CheckBox ID="cbCerts" runat="server" checked="false" AutoPostBack="true" />Certs</td> <td><asp:CheckBox ID="cbBrochures" runat="server" checked="false" AutoPostBack="true" />Brochures</td> </tr> </table> </ContentTemplate> </asp:UpdatePanel> </td> </tr> </asp:Panel>

The UpdatePanel prefer to work within a DIV or a SPAN object. Try setting the RenderMode property of the UpdatePanel toInline


See it here for RenderMode property, try to set it

http://www.asp.net/AJAX/Documentation/Live/mref/P_System_Web_UI_UpdatePanel_RenderMode.aspx

See for most common problem of UpdatePanel

http://blogs.visoftinc.com/archive/2007/09/23/asp.net-ajax--updatepanel-not-working--common-problems.aspx

Monday, March 26, 2012

Will atlas:updatepanel and asp:fileupload ever be friends?

Just wondering if there ever will be support for postbacks inside a updatepanel.

Possible by adding a mode "Triggered" to the updatepanel's Mode list.
This mode could make the updatepanel only update when it's triggered by a trigger from the trigger list, or by myupdatepanel.update();

hello.

well, i'd say no you won't be able to do that. i guess that the problem is that you can't get the bytes from the input type="file" with jscript...


I know it's not possible in the current build :\

Just wondering if there is any planes to make this happen in any of the next atlas builds..
Or is it simply not possible to not trigger atlas within the updatepanel when triggering a postback?

hello.

what i was trying to say was that the problem was not related with the current build but with the way the <input type="file"> works. if i'm not mistaken, you can't get the bytes of the file by using javascript. due to this, atlas won't be able to get them too since what it does (when it performs a postback) is to go through all the controls of the form and get their values which are packed on a string that is sent back to the server. since you can't get the bytes of the file through javascript, i think that what you wask won't be possible ...though i hope i'm wrong ;)


Yes i understand that :)
But what i was hoping for, was a atlas:updatepanel mode, that enabled it to only do the javascript postback if a atlas trigger was used, or a updatepanel.update();

This would enable all controls that do a normal postback but are't stated in the triggers list, to send a normal postback.

Good example of my problem now:

My page is build up so if the user logs in, his options pops up without page refresh.
This is a picture gallery and when you log in, you can see "new album, new picture" etc..

The problem here is that i can't get the UploadPanel to be visible, since the "new picture" button is inside a updatepanel, and the uploadpanel is't.
And I cannot upload a picture if the uploadpanel is inside a atlas:updatepanel cause it won't send the file :s

So either I need to be able to run a normal postback inside a updatepanel, without atlas taking over the event, or I can't view the "new picture" link before the page has been refreshed one time.

hello.

i didn't understand the visibility problem associated with the updatepanel. can you show me the declaration of the udpatepanel? how are you hiding it? i hope that you're using css styles to do that (if you're using the visible property i'm willing to bet that the control isn't being rendered on the final page


hello.

i didn't understand the visibility problem associated with the updatepanel. can you show me the declaration of the udpatepanel? how are you hiding it? i hope that you're using css styles to do that (if you're using the visible property i'm willing to bet that the control isn't being rendered on the final page)


For now i've been using a asp:panel with visibilty value inside a updatepanel.
And then used panel.visible = true; and updatepanel.update();

With the sample code here.
Your just logged in, and you now get to view the linkbutton "Upload".
The linkbutton needs to be inside a updatepanel, since it could be displayed without pagerefresh when the user logs in.
Since it's inside a updatepanel, it can only trigger atlas postbacks, and no refreshed postbacks.
Therefore my uploadpanel also needs a updatepanel wrapped around, so it will be visible when you push the upload linkbutton. (again without page refresh)
But since the fileupload is inside a updatepanel, the fileupload won't do a real postback, and therefoer the file is't uploaded..

Solutions:
Is there a way to get the fileupload to do a valid postback, even tho it's inside a updatepanel?
Is there another way to display my fileuploadpanel with or without pagerefresh from a linkbutton within a updatepanel?

Very simple code:

<atlas:UpdatePanel ID="UploadLinkUpdatePanel" runat="server" Mode="Conditional"> <ContentTemplate> <asp:LinkButton ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" /> </ContentTemplate></atlas:UpdatePanel><atlas:UpdatePanel ID="FileUploadUpdatePanel" runat="server" Mode="Conditional"> <ContentTemplate> <asp:Panel ID="FileUploadPanel" runat="server" Visible="false"> <asp:FileUpload ID="FileUpload" runat="server" /> </asp:Panel> </ContentTemplate></atlas:UpdatePanel>
protected void Upload_Click(object sender, EventArgs e) { FileUploadPanel.Visible =true; FileUploadUpdatePanel.Update(); }

hello.

several things here: 1st, i'd use only a panel (or even a simple div control) to hide the uploadfile control. when you set the visible property of a control to false, that control will not generate HTML that is sent to the client. this is not probably what you want...

setting the mode of the updatepanel to conditional will also have different results here. this means that only one panel will be refreshed and this can be caused by a server side event fired by a control placed inside the panel or by an external control configured as a trigger.

so, in this case, i'd do the following:

1. remove the 2nd updatepanel

2. configure the visibility of the panel without using the visible property (use the css disply property)

3. use the postbackaction associated with the button (yes, use the xml script) and set it so that the target is the link button (since i haven't tried it, i'm having some doubts about this...it might not work very well...you might have to add a dummy button outside the panel so that it really makes a complete postback)

hope this helps.


First of, Can i hide\show a panel\div without using atlas?
If this is possible (without refreshing the whole page), then i might be able to do a workaround..

I'm using all these updatepanels with panels inside, so that when a user logs into my gallery, the list of albums\pictures in the current album is updated according to the users permissions,
But also admin stuff is visible, like create album etc..

All this happens without the page refreshing at all, and it's looking pretty nice :)
So the only problem now is to get the fileupload to post (and work)..

I want to have it inside a updatepanel so i can display the form without page refresh, but atm i have no idea what to do :\

PS: Demo page ishttp://vakuum.mine.nu (VERY slow)


hello.

well, you can hide/show the panel without updateanel. the updatepanel is cool because it let's you handle server side events without doing a complete postback. to show/hide an element you don't need an update panel. if i'm not mistaken, the asp.net panel control generates a div element. since you know its id, then you can simply write this javascript code to hide the panel:

document.getElementById("id of the asp.net panel").style.display = "none";

and to make it visible, just do something like this:

document.getElementById("id of the asp.net panel").style.display = "block";


Thanks =)
That just solved half of my problem :)

Now i need to set display = "none" if any other button is clicked.. guessing that will be hard :\
Hi, I have some kind of similar problem with a filupload control and updatepanels. So I wrote script to hide the fileupload on the pageload, and show/hide it whenever I need it.
I used page.registerstartupscript("shide, strshowhidescript") on every place I need it, but it never works when I call it in the method that handles an event from a button that's in the update panel. the code from that button works when I do step into, but On the screen there are no change, not even from the other code in that button which worked before I added the script. Any idea how I can overcome this?
thx.

hello.

can you show the client script code you're registering? thanks.

Will calling .click() fire an updatepanel Trigger?

This might seem a bit silly but...

Basically, I have a javascript function which calls the .click() method of a button, this button resides outside of any UpdatePanels

This button is also set as a trigger for one of my UpdatePanel controls.

My problem is, the button click runs fine, the server side click event fires ok and rebinds some data for a GridView which is inside the UpdatePanel, but the UpdatePanel does not update its contents.

Do you have to physically click the button with your mouse to cause the Trigger? Or should the programmatic javascript call to click() work?

No will not cause it trigger, you need a postback for that, not a javascript call


You cantrigger an UpdatePanel refresh from the client side, using __doPostBack().

Hi

The programmatic javascript call to click() should work, you must do something wrong.

Look this sample:

<%@. Page Language="C#" %>

<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<link href="http://links.10026.com/?link=StyleSheet.css" mce_href="StyleSheet.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
var styleToSelect;
function onOk() {
$get('Paragraph1').className = styleToSelect;
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<p id="Paragraph1">
GetContentFillerTextGetContentFillerTextGetContentFillerTextGetContentFillerText</p>
<br />
<ajaxToolkit:Accordion ID="Accordion1" runat="server" ContentCssClass="grey" FadeTransitions="false"
FramesPerSecond="25" TransitionDuration="250" HeaderCssClass="dimgreen" EnableViewState="true">
<Panes>
<ajaxToolkit:AccordionPane runat="server" ID="PaneOne">
<Header>
AccordionPane0
</Header>
<Content>
<a href="http://links.10026.com/?link=javascript:return false" onclick="javascript: LinkButton1.click()">Click here to change
the paragraph style</a>

</Content>
</ajaxToolkit:AccordionPane>
</Panes>
</ajaxToolkit:Accordion>
<div style="visibility: hidden">
<asp:LinkButton ID="LinkButton1" runat="server" Text="Click here to change the paragraph style" /></div>
<asp:Panel ID="Panel1" runat="server" Style="display: none" CssClass="modalPopup">
<asp:Panel ID="Panel3" runat="server" Style="cursor: move; background-color: #DDDDDD;
border: solid 1px Gray; color: Black">
<div>
<p>
Choose the paragraph style you would like:</p>
</div>
</asp:Panel>
<div>
<p>
<input type="radio" name="Radio" id="RadioA" checked="checked" onclick="styleToSelect = 'sampleStyleA';" />
<label for="RadioA" class="sampleStyleA" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p>
<input type="radio" name="Radio" id="RadioB" onclick="styleToSelect = 'sampleStyleB';" />
<label for="RadioB" class="sampleStyleB" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p>
<input type="radio" name="Radio" id="RadioC" onclick="styleToSelect = 'sampleStyleC';" />
<label for="RadioC" class="sampleStyleC" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p>
<input type="radio" name="Radio" id="RadioD" onclick="styleToSelect = 'sampleStyleD';" />
<label for="RadioD" class="sampleStyleD" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p style="text-align: center;">
<asp:Button ID="OkButton" runat="server" Text="OK" />
<asp:Button ID="CancelButton" runat="server" Text="Cancel" />
</p>
</div>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender" runat="server"TargetControlID="LinkButton1"
PopupControlID="Panel1" BackgroundCssClass="modalBackground" OkControlID="OkButton"
OnOkScript="onOk()" CancelControlID="CancelButton" DropShadow="true" PopupDragHandleControlID="Panel3" />
</div>
</form>
</body>
</html>

Thanks

window.debug.isDebug is null or not an object

I have user control which contains UpdatePanel. For UpdatePanel I have tried to put UpdatePanelAnimationExtender, but there's coming javascipt error which says "window.debug.isDebug is null or not an object". Without UpdatePanelAnimationExtender UpdatePanel is working great. I'm using ASP.NET 2.0 and latest AJAX Framework and ControlToolkit. What could be wrong?

Thanks
juster

You likely have old scripts from an AJAX CTP or Beta cached on your web server or on your browser. Reset IIS and make sure you do a CTRL-F5 on your browser.

window.debug.isDebug is null

While using updatepanel, I'm getting a javascript error window.debug.isDebug is null. Though updatepanel gets updated, some events like ajaxcontroltoolkit's updatepanelanimation etc. are not working. I am experiencing this problem only in machine where AJAX Futures December CTP was installed. Before installing AJAX I have removed all previous ajax versions also. Anyone else met with the same kind of error?

Maybe your AjaxToolkit isn't newest,The newest version haven't the problem.

Window.OnLoad and callback problem

Hi,

I have a Javascript function that fires every time the page loads: triggered by the event window.onload...

Now i use an updatepanel and i need that function to be fired every time the callback occurs...

Wich is the event i should use?

Is there something like window.oncallback ?

Thanks in advance.

Antonio Li Causi.

Well, no. First, if you're using the ASP.Net ajax framework anyway, you're better off writing a function called pageLoad; the framework looks for it and fires it once everythign's done and ready to go on the first load. It's better than window.onload for this b/c it's coordinated w/ everything else the framework is trying to do for you.

In that pageLoad() method, you want to enter the line: Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler) where pageLoadedHandler is the name of the function you want to fire when the page loads after async callback.

Example is here:http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerPageLoadedEvent.aspx


Check this:ASP.NET AJAX Client Life-Cycle Events

and especiallypageLoaded Event

Saturday, March 24, 2012

Wizard Control with Validation in UpdatePanel

Hi, I met a problem that I don't know how to solve when using a Wizard control with Validation in updatePanel. I am using ASP.NET 2.0 and ASP.NET 2.0 AJAX Extension 1.0. Below is the sample code and the problem I had is that after I went to Step 2 if I click Previous Button to go back to Step 1, the validator is not showing its validation result. Did I do anything wrong in my code? Would appreciate if anyone could help! Also, got a side question that how do I preserve the value in a password TextBox if I am going from Step 2 to Step 1, i.e. if the TextBox1's TextMode is set to Password, is there anyway to preserve its value?

<

formid="form1"runat="server">
<asp:ScriptManagerID="ScriptMan"runat="server" />
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:WizardID="Wizard1"runat="server"DisplaySideBar="false">
<WizardSteps>
<asp:TemplatedWizardStepID="TemplatedWizardStep1"runat="server"StepType="Start"Title="step 1">
<ContentTemplate>
Step 1<br/>
ASDF:
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="TextBox1"ValidationGroup="asdf"ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
</ContentTemplate>
<CustomNavigationTemplate>
<asp:ButtonID="StepNextButton"runat="server"CommandName="MoveNext"Text="Next"CausesValidation="true"ValidationGroup="asdf"/>
</CustomNavigationTemplate>
</asp:TemplatedWizardStep>
<asp:TemplatedWizardStepID="TemplatedWizardStep2"runat="server"StepType="Finish"Title="step 2">
<ContentTemplate>
Step 2
</ContentTemplate>
<CustomNavigationTemplate>
<asp:ButtonID="FinishPreviousButton"runat="server"CausesValidation="False"CommandName="MovePrevious"Text="Previous"/>
<asp:ButtonID="FinishButton"runat="server"CommandName="MoveComplete"Text="Finish"/>
</CustomNavigationTemplate>
</asp:TemplatedWizardStep>
<asp:TemplatedWizardStepID="TemplatedWizardStep3"runat="server"StepType="Complete"Title="Complete">
<ContentTemplate>
Complete
</ContentTemplate>
<CustomNavigationTemplate>
<asp:ButtonID="ContinueButton"runat="server"CausesValidation="False"CommandName="Continue"Text="Continue"/>
</CustomNavigationTemplate>
</asp:TemplatedWizardStep>
</WizardSteps>
</asp:Wizard>
</ContentTemplate>
</asp:UpdatePanel>
</form>Hi, my bad that I did not do enough researching before this posting, the problem has been resolved after I fonudthis blog entry of Matt Gibbs. It turns out that it is a known issue perhttp://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx, and the workaround is to disable ClientScript of the validator controls. However, if you don't like the round trip traffic, Matt has posted Ajax Validators. I was not aware of this since I did not join the beta/CTP of the ASP.NET AJAX.

Validators are not compatablw with ASP.NET AJAX Final version..

Check this link

http://weblogs.asp.net/scottgu/archive/2007/01/25/links-to-asp-net-ajax-1-0-resources-and-answers-to-some-common-questions.aspx

You can download the stable version of Validators from here

http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx


Johnny, I am curious if you ever found a solution to your other problem about losing the password value going from step 1 to step 2. I am currently facingt the same issue and I have found no answers.

I am casting the password box in the following way:

// make reference to the password step
TemplatedWizardStep passwordStep = SelectPasswordStep;

// password step
TextBox PasswordChoice =
(TextBox)passwordStep.ContentTemplateContainer.FindControl("Password");

Response.Write(PasswordChoice.Text);

When I have the Password control set as textmode=password the text value returns blank. No error, just an empty value. When I have the textmode as singleline it works. Something about a textmode of password seems to make the control lose its value. Anybody have any ideas. Is this a bug or by design for some Redmond reason?

- jq



Chetan, thanks for you replay.

Jq, I was not working the "side problem" right now, however, I think you can preserve the actuall password string when going from step 1 to step 2, and when you go back to step 1, u could assign the password back to textbox. I guess it's not a bug and should be deisgned to be that way for security reason. I hope the work around could work, if you are going try this out, please let me know the result. Thanks.


I actually wasn't even able to get to this point. My problem is that I can't do ANYTHING with the password textbox control. Moving to the next step, referencing the control via code-behind, or anything -- once I have moved past the step with the password control, I lose the value.

So when I'm at the end of the wizard and I'm creating my account, I have lost my password value. So I can't even create the account, making my entire wizard useless. With your solution, can you read the value of the password field? If so would you mind posting your code?

Thanks,

JQ

Wizard Control, UpdatePanel, and Validation causes error in webresource.axd Bug

I have a wizard control with several steps, some of which use control validation. When placed inside an Ajax UpdatePanel, the webresource.axd javascript is no longer able to reference the controls validated in the previous step, and halts on:

WebResource.axdfunction ValidatorGetValue(id) { var control; control = document.getElementById(id); if (typeof(control.value) == "string") { return control.value; } return ValidatorGetValueRecursive(control);}

where the document.getElementById(id); returns null.

A workaround is to disable clientside validation on all validation controls, which is not a great loss when using ajax, but utterly annoying when you have gone to all the trouble of writing javascript for custom validation controls, etc.

The cause is probably complex, so I shall not comment on how it should be resolved. I assume, however, that the javascript is correct in that the controls not being rendered are in fact to be found in the DOM.

At least in my case, it would be nice if the javascript checked for null and ignored the control if it wasn't there.

Anyhow, it would be much appreciated if someone would look into it.

Thanks

In Atlas 1.0 we have updated versions of the validators that are compatible with UpdatePanel. In the current CTP I'm afraid that you'll have to use some workaround.

Thanks,

Eilon


This sounds like it could be related to my problem:

http://forums.asp.net/thread/1412888.aspx

What work arounds are available for this issue? At the moment I'm displaying all the controls in divs and just hiding them, which is pretty horrible.

Thanks,

Paul

Working with JeffZs AjaxFileUploadHelper

Hello,

While everyone has their own preferred way to tackle the UpdatePanel / FileUpload issue, JeffZ's workaround postedhere is very promising, though through experimenting with it I have experienced two show-stopping bugs:

- Firefox activity never ceases after a successful upload, it simply continues to appear as though it is active, and the cursor remains on an operation image. This would be just extremely annoying/unusable except that it prevents future custom scripts that you've registered from running.

- In both Firefox and IE, attempting to access login controls (i.e. Log Off) while on a page or usercontrol implementing the helper will cause a 500 error.

Otherwise, the results in IE are very compelling, and it's very close to beingthesolution (other than buying something) for everyone looking to have their async upload cake and eat it too. Has anyone else worked with this workaround and have you been able to solve the problems introduced using this approach?


Hi

I'm afraid that I'm not familiar with that contorl.

After some google,I found:http://jeffzon.net/Blog/post/AjaxFileUploadHelper-updated-to-v11.aspx

I suggest that you post issues to their official forums or Email to Jeffrey Zhao,Thanks!

Hope this helps you.

Wednesday, March 21, 2012

Wrapping a Login control with an UpdatePanel

Hi All,

This is my first ATLAS experiment. I'm trying to warp a Login control with an UpdatePanel. It seems that putting the UpdatePanel inside a template is not possible, which leaves me with the option of putting the Login control inside the ContentTemplate of the UpdatePanel instead. However, this results in the TriggerControlEvent not being able to reference the login button (which has to reside within the Login control in order to work, no?)

Kind of a chicken an egg problem it seems. Anyone has an idea how to acheive this behaviour?

Thanks,

Yuval

Just found out that the ControlTriggerEvent is not required, so no problem there.


hello.

1. you don't need a trigger if the control that has an event you want to handle is inside an updatepanel. the panel will detect the postback and treat it accordingly.

2. there are known issues that won't let you put the login control inside an update panel (search the foruns for a complete description of the problem).

Writing Javascript at Runtime on Update

Ok, I can't seem to find a shred of working advice on this topic. But, here are the basics.

Button inside of an updatepanel. Partial rendering is turned on.

Button gets clicked. Ajax call is made to the server. How do I at this point write javascript to the client's box that will execute, such as an alert.

Can't use Response.Write. Can't use ClientScript.Register... since that requires a full postback, unless I'm missing something. So...I'm not really sure what my other options are, surely someone else has run across this already. If you have any insight please share it with me.

Use EVAL() function of Javascript. It can be used as following,

<SCRIPT language="Javascript">

function Popup()

{

ExecJavascript("alert('Hi All');");

}

function ExecJavascript(var jscript);

{

eval(jscript);

}

</SCRIPT>


Use ScriptManager.RegisterStartupScript. Here's a working example:

<%@. Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> private void button_click(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(up1, up1.GetType(), "myscript", "alert('Alert sent from server!')", true); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Button ID="button1" runat="server" Text="Click Me" OnClick="button_click" /> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

hello.

or, if you don't need to return anything from the server, you can also hande the endrequest event of the client pagerequestmanager object which is available in all the pages that have updatepanels.

<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest( endRequest );

function endRequest( sender, e ) {
//put your code here.
}
</script


Perhaps I was not clear.

madesh, Your code is only from javascript to javascript. That isn't the issue.

Steve Marx, You don't have partial rendering enabled. You will find that enabling that will prevent your button from registering that script block because doing that requires a full post back.

Luis Abreu, I do need to send info back from the server.

Let me restate the problem. You're on the server, there isn't any javascript already on the client. You need to write some JS to the client, from a partial postback. ie, they just pressed the button, but it was through AJAX which means no script registering through the ClientScript object. So, during this partial post back, what are my options for sending a script block to the client?


Crap miss-read that Steve, I haven't tried it with the script manager, ill give that a shot when i get home. Why can't we edit posts?...


Excellent. Thanks Steve it worked. The trick is, you can't use Page as the control to register the script with. You have to use an existing control on the page, any will do. Even the update panel (up1). Thanks.

ZeroDegrez:

madesh, Your code is only from javascript to javascript. That isn't the issue.

Let me restate the problem. You're on the server, there isn't any javascript already on the client. You need to write some JS to the client, from a partial postback. ie, they just pressed the button, but it was through AJAX which means no script registering through the ClientScript object. So, during this partial post back, what are my options for sending a script block to the client?

As you stated that it is a AJAX call and Javascript gets generated on server side. EVAL can help you. Return your server generated Javascript to Client side as a string(Output of your AJAX call). Execute that Javascript on Client side using EVAL function.

This way you can execute the javascript returned by your AJAX call on client side.

<SCRIPT language="Javascript">

function AJAXcall()

{

var JScript={Put your AJAX call here};

ExecJScript(JScript);

}

function ExecJScript(var JScript)

{

eval(JScript);

}

</SCRIPT>

Wrong EventName triggers. How come?

Hi

In the project I have two GridViews: master GridView1 and slave GridView2. The latter resides on the UpdatePanel with properties as follows:

AsynchPostBack ControlID=GridView1

EventName=SelectedIndexChanging

It works fine: if I select a row from GridView1, partial postback takes place and GridView2 re-populated

But! If I set GridView1.AllowSorting=true and click on any of GridView1 titles, it goes again with the partial postback! I don't have my GridView1.Sorting event handler in the list of UpdatePanel.ControlID but it acts as well it is.

How can I prevent a partial postpack in the case above? I need my page be sent as full old-way post back, when click on the GridView1 headers.

Hi Mabanza,

Mabanza:

But! If I set GridView1.AllowSorting=true and click on any of GridView1 titles, it goes again with the partial postback! I don't have my GridView1.Sorting event handler in the list of UpdatePanel.ControlID but it acts as well it is.

this sounds like you've let UpdatePanels UpdateMode on the default valueAllways. Please set it toConditional.


This relates to the children updates. Anyway, I did, no effect.

This boiled down to the follows, actually. I can not register the title (which is LinkButton on the server) as

RegisterPostBackControl(LinkButton);

It works the same wrong way - as partial post back.

How to register LinkButton for full postback?

Thanks.


May try use another way to go. Instead declaring the SelectedIndexChanging event as trigger, use in the SelectedIndexChanched event updatepanelsUpdate() method. eg.

void GridView1_SelectedIndexChanged(Object sender, EventArgs e){// Your logic here UpdatePanel1.Update();}

So you be sure, updatepanel only updates on changing the selected index from your gridview.


Good idea. But it does not suit me. I have

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest) andadd_beginRequest(StartRequest) hooked.

If I update panel on the server side, I won't be able to use that, right?

Thanks.


Mabanza:

If I update panel on the server side, I won't be able to use that, right?

not sure about that. To put it bluntly, i'm not a fan from javascriptCool Anyway.

Mabanza:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest) andadd_beginRequest(StartRequest) hooked.

I dont now where in the page lifecycle these events are fired, but for updating the gridview after page index changing, a roundtrip to the server is required. From my point, let the javascript beginRequest and endRequest events still active, give the UpdatePanel.Update method a try and look whats up on your page.

WYSIWYG text editor compatible with UpdatePanel

Does anyone know of a WYSIWYG Text Editor that works when placed inside an UpdatePanel? I tried two (FckEditor and obout's editor). Both of them failed. Thanks!

http://forums.asp.net/p/1028530/1406390.aspx#1406390

Thanks! this is exactly what i needed

Smile