Showing posts with label runat. Show all posts
Showing posts with label runat. Show all posts

Monday, March 26, 2012

Updating an UpdatePanel only when certain item is clicked in Datalist

I have 2 UpdatePanels each with a Datalist in them. Here is my code:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DataList2" />
</Triggers>
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" DataSourceID="Ods1"BorderStyle="Solid" GridLines="Both" RepeatDirection="Horizontal">
<ItemTemplate>
<asp:ImageButton ID="ThumbImage1" runat="server"ImageUrl='<imagepath...>' />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:DataList ID="DataList2" runat="server" RepeatColumns="4"DataSourceID="Ods2" BorderStyle="Solid" GridLines="Both"RepeatDirection="Horizontal" OnItemCommand="DataList2_ItemCommand"CellPadding="5">
<ItemTemplate>
<asp:ImageButton ID="ThumbImage2" runat="server"ImageUrl='<imagepath...>' CommandName="ThumbImage"CommandArgument='<passing the id...>' />
<br />
<asp:ImageButton ID="DeleteImage" runat="server"ImageUrl="images/delete.gif" CommandName="DeleteImage"CommandArgument='<passing the id...>' />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>

and the code in DataList2_ItemCommand is as follows:

protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "DeleteImage")
{
//code to delete the image from database

...
this.DataList2.DataBind();
this.UpdatePanel2.Update();
}
else if (e.CommandName == "ThumbImage2")
{
//code to add the thumb image to the table attached to datalist1.
...
...
this.Datalist1.DataBind();
this.UpdatePanel1.Update();
}
}

As you can see in the above code, I want to update the UpdatePanel1 only when the imagebutton "ThumbImage2" is clicked and NOT when the imagebutton "DeleteImage" is clicked in Datalist2. But because Datalist2 is the cause of the AsyncPostBackTrigger for UpdatePanel1, it is updated when either one of the imagebuttons are clicked. Is there a way to change this?

Please help.

You don't want to set the datalist as the trigger, you want to set the individual ImageButtons as the triggers. Remove the triggers from UpdatePanel1, as well as the UpdateMode="Conditional".

<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
...
</ContentTemplate>
</asp:UpdatePanel>

Then in the DataList2_ItemDatabound event, add the following:

ProtectedSub DataList2_ItemDataBound(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.DataListItemEventArgs)Handles DataList2.ItemDataBound
Dim ibtnAs ImageButton =CType(e.Item.FindControl("ThumbImage2"), ImageButton)
Dim trggrAsNew AsyncPostBackTrigger
trggr.ControlID = ibtn.ClientID
trggr.EventName ="Click"
UpdatePanel1.Triggers.Add(trggr)
EndSub


In the ItemCommand event, I am executing some server side code for the imagebutton that was clicked in that specific row of datalist based on its id (which I retrieve using e.CommandArgument).

If I use the approach that you mentioned above, how do i retrieve the database id of the image clicked?

Thanks


DataList2.DataKeys.Item(e.Item.ItemIndex)


The solution you suggested works like a charm. I removed the datalist as the trigger & added the imagebutton as trigger in ItemDataBound event. Also, I still execute the server side code in ItemCommand event based on the which button clicked & everything works fine.

Thanks a ton.

Saturday, March 24, 2012

Uploading file during onchange

I try to upload file in server during user select file:

<inputid="iupload"runat="server" type="file"style="width:1px"/>
<inputtype="hidden"id="hdName"runat="server"/>

<scriptlanguage="javascript">
function Doo(){
document.getElementById('hdName').value = document.getElementById('iupload').value;// to check path
WebForm_DoCallback('__Page',document.getElementById('iupload').value,CallbackFunction,'context',null,false);returnfalse;
}
</script>

and on server side:

protectedvoid Page_Load(object sender, EventArgs e)
{
string argClientFunction ="";
string cScript = ClientScript.GetCallbackEventReference(this, argClientFunction,"CallbackFunction","'context'","null",false);
string f=@dotnet.itags.org."
javascript:Doo();";
iupload.Attributes.Add("onchange", f);

string scr ="<script language=javascript>";
scr +="function CallbackFunction(result, context)";
scr +="{";
scr +="document.getElementById('spUploaded').innerText += 'Done';";
scr +=" return false;";
scr +="}";
scr +="</script>";
RegisterStartupScript("scr" +this.ClientID, scr);

}


publicvoid UploadFile(string fileName)
{
// try to upload file to server
}
publicstring GetCallbackResult()
{
UploadFile(evArg);

evArg = String.Empty;

return evArg;
}
publicvoid RaiseCallbackEvent(string eventArgument)
{
evArg = eventArgument;
}

Problem occur in UploadFile(...): When I try to get iupload.PostedFile for file uploading it's null. I can get file name only.

How can I upload file normally without postback with onchange ?

I need upload file to server as Gmail or Yahoo Mail!

File uploads require a full postback. There has been a lot of talk on here about sites such as gmail that appear to asynchronously load a file. At this point, the only way that I have heard of this successfully implemented is by using IFrames and have another page that does the full postback, but doesn't look like it.


Thank you! I have heard about Iftame to upload files. Have you any information about this?


Not really... we haven't got into handling file uploads very often, and if we do, we would probably use the telerik fileupload control since we have the suite and I believe it handles very large files much better that the built in fileupload for asp.net. When I tested both of them, I was able to crash IIS with the built in control by trying to upload a dvd image because it seemed to check for the file size only after it had been processed through IIS, but the telerik control seemed to do that in pieces which didn't cause it to lock up.

Wednesday, March 21, 2012

Urgent: AutoCompleteExtender doesnt work/Updatepanel doesnt work

This is my code for the AutoCompleteExtender

<asp:textboxid="txtQuickSearch"runat="server"CssClass="inputText"style="width:145px; "></asp:textbox>

<atlas:AutoCompleteExtenderrunat="server"ID="acSearch">

<atlas:AutoCompletePropertiesTargetControlID="txtQuickSearch"Enabled="True"ServicePath="http://localhost/Sony.BusinessSuite.Web.UI/AtlasServices/MasterData.asmx"ServiceMethod="GetAllModels"minimumprefixlength="2"/></atlas:AutoCompleteExtender>

When i start typing fiddler shows:

#ResultHostURLBodyCachingContent-TypeUser-defined1401localhost

/Sony.BusinessSuite.Web.UI/AtlasServices/MasterData.asmx?mn=GetAllModels

4.431text/html

The same happens with an update panel...

basically i've been trying to use atlas things in the application we are working on here for about 3 weeks now... and up until now it has been very cumbersome and time consuming.

Hi,

Could you post the code for the method you are using in your webservice

Thanks


Hi,

you are getting a 401. I believe that it happens because you are trying to access a web service in another domain and this is not allowed in normal conditions. Please checkthis thread.

Here's the webservice code, thanks in advance to have a look...

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

[ToolboxItem(false)]

publicclassMasterdata :WebService

{

[WebMethod]

publicstring[] GetAllModels(string prefixText,int count)

{

ArrayList filteredList =newArrayList();

//Get the available product categories from the principal object.

Principal principal = (Principal)Context.User;

List<Category> myCategories = principal.Categories;

List<DKCategory> myDKCategories =newList<DKCategory>();

foreach (Category catin myCategories)

myDKCategories.Add(newDKCategory(cat.OID));

//Get the models from the masterdata service (limited to the users available categories).

Proxy.Pricing.Model.ModelService ModelSVC =new Proxy.Pricing.Model.ModelService();

List<Model> myModelsSVC = ModelSVC.GetModels(myDKCategories,null);

foreach (Model modin myModelsSVC)

{

if (mod.Name.ToLower().StartsWith(prefixText.ToLower()))

filteredList.Add(mod.Name);

}

return (string[])filteredList.ToArray(typeof(string));

}

}


Hi,

I tried the solution in the thread you suggested, but it didn't work. I don't think it is related to this though, because the webservice i'm calling is in the same project than the page consuming it.

Could the problem be related to the fact i'm using the "web application project"? or nested masterpages?

Wesley


hello.

what response do you get from fiddler?


Hi,

Have you tried using as RelativePath within your ServicePath parameter?

Regards

Use a DragPanelExtender and an AlwaysVisibleControlExtender component at the same time pro

<asp:Panel ID="Panel3" runat="server" Height="3333px" Width="3333px">
<asp:Panel ID="Panel1" runat="server" Height="150px" Width="125px" BackColor="black">
<asp:Panel ID="Panel2" runat="server" Height="25px" Width="125px" BackColor="Blue">
</asp:Panel>
</asp:Panel>
</asp:Panel>
<cc1:DragPanelExtender ID="DragPanelExtender1" runat="server" TargetControlID="Panel1" DragHandleID="Panel2">
</cc1:DragPanelExtender>
<cc1:AlwaysVisibleControlExtender ID="AlwaysVisibleControlExtender1" runat="server" TargetControlID="Panel1">
</cc1:AlwaysVisibleControlExtender>

I use a DragPanelExtender and an AlwaysVisibleControlExtendercomponent at the same time.
It works perfectly if I don't scroll the web page.
After I scroll the web page, the drag and drop behavior notworks properly. When I drag the Panel2, the Panel1 will disappear until I dropthe Panel2, the Panel1 will appear again.
Does anyone know how to solve this problem?

Does anyone know how to solve the problem?


Hi Vincent901529,

I have tested your sample and I think this issue is cuased by the scroll offset. I suggest that you should post it to CodePlex. If you insist on resolve it by yourself. We suggest that you should move the Panel to its right place on its mousedown event. You can modify on the mouseDownHandler (Line : 140 V11119) in the FloatingBehavior.js under the DragPanel directory.

 function mouseDownHandler(ev) { window._event = ev; var el = this.get_element(); if (this.checkCanDrag(ev.target)) { //new added logic.
 .... ; // calculate the new location.
$common.setLocation(el, newLocation); // reset the showing position.
 _dragStartLocation = $common.getLocation(el); ev.preventDefault(); this.startDragDrop(el); } }
  Best regards,
Jonathan

Many thanks for your replying.

It is very helpful.