Finding control In Ajax Tab container

27 09 2008

Suppose you have a repeater control inside ajax tab container and you want to bind data with that repeater. If on your page you try to directly bind data with it, it will generate error and say that “repeater is not found”.

You have to first find the repeater and then you can do all the things with it as you do in normal .

Control myControl = TabContainer1.Tabs[0].FindControl(“RepeaterName”);

Repeater MyRepeater = (Repeater)myControl;

or simply in single step

Repeater MyRepeater =(Repeater)TabContainer1.Tabs[0].FindControl(“RepeaterName“);

Now you can bind data with it or do any operation with this repeater.

Hopefully it will help, if find helpful please leave a comment





The state information is invalid for this page and might be corrupted

26 06 2008

IN one of my project, I was getting this error in Mozilla Firefox only that whenever i clicked a button or link.

It is because of the fact that firefox caches the form fields. Two ways to encounter this problem.

1.Write following snipet in your cs file

protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
if (Request.Browser.MSDomVersion.Major == 0) // If it is Non IE Browser
{
Response.Cache.SetNoStore();
}
}

2. In page load, write following statemet

Response.Cache.SetNoStore();

Now error has been removed and you can sleep with satisfaction.

Muhammad Tahir Rauf.





Ajax based FileUploading

16 06 2008

I had an ajax based asp.net page which was working perfectly and i was happy. On same page when i put a file upload control the whole page becomes non-AJAX.

During search on GOOGLE, I found that you can not make the file uploader AJAX BASED. However what you can is that, you can enforce a “FULL POST BACK” for file uploader. In this way all other things on page remains ajax based.

TO do this, just do as follow

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
   <ContentTemplate>
      <asp:FileUpload ID="FileUpload1" runat="server" />
      <asp:Button ID="btnUploadFile" runat="server" Text="Upload" />
   </ContentTemplate>
</asp:UpdatePanel>
In above snip est, you have a file upload control and a button btnUploadFile which will perform file upload.

You have to write a postback trigger on this button to enable full postback

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
 <Triggers>
    <asp:PostBackTrigger ControlID="Button1" />
 </Triggers>
 <ContentTemplate>
     ..
     ..
     ..

This is  all which you have to do to make your page AJAX ENABLED with FILEUPload.
CHEERS