linkbutton doesn't work for updatepanel - asp.net

I have set of link buttons outside update panel but when click any one of them they donot work at all , when i set the postbackUrl they make full postback
my source code:
<asp:Panel ID="pnl_viewImages" runat="server">
<asp:Label ID="lbl_viewImages" runat="server" style="texalign: left"
Text="view images :"></asp:Label>
<br />
<br />
<br />
<table cellpadding="0" cellspacing="0" style="width: 100%" class ="Alternating">
<tr>
<td colspan="5">
<asp:UpdatePanel ID="updatePnl_image" runat="server">
<ContentTemplate>
<asp:ListView ID="lv_showImages" runat="server">
<ItemTemplate>
<asp:Image ID="img_showNewsImage0" runat="server" Height="300px"
ImageUrl='<%# "RetreiveImage.ashx" %>' Width="413px" />
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbtn_first" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lbtn_last" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lbtn_next" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lbtn_previous" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lbtn_delete" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lbtn_first" runat="server" onclick="lbtn_first_Click">first</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lbtn_previous" runat="server" onclick="lbtn_first_Click"><<</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lbtn_next" runat="server" onclick="lbtn_first_Click"
>>></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lbtn_last" runat="server" onclick="lbtn_first_Click">last</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lbtn_delete" runat="server" onclick="lbtn_first_Click">delete</asp:LinkButton>
</td>
</tr>
</table>
<br />
i tried to remove the table but in vain it does not work also.

You need to put the LinkButtons in the UpdatePanel or put them in their own UpdatePanel.

You appear to be missing a ScriptManger defined before your update panel such as
<asp:ScriptManager ID="ScriptManager1" runat ="server"></asp:ScriptManager>
I think that is probably causing your problem.
Controls outside of the panel can invoke a partial postback.
Paul

Related

Trigger's updatepanel in a another updatepanel

I've two updatePanel :
the first :
<asp:Panel ID="pnlConso" runat="server" Height="500px" ScrollBars="Auto">
<asp:UpdatePanel ID="upConsommateur" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tbLogin" EventName="TextChanged" />
<asp:AsyncPostBackTrigger ControlID="btnValiderAjout" EventName="Click" />
</Triggers>
<ContentTemplate>
...
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
and the second :
<asp:UpdatePanel ID="upAjoutConso" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlAjoutConsommateur" runat="server" CssClass="invisible">
<table>
...
<tr>
<td>
<asp:Button ID="btnValiderAjout" runat="server" Text="Valider" CssClass="invisible" />
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
then my problem is when I click on the btnValiderAjout the first panel don't update.
I make this button such as a trigger for the first but it don't update ... What I'm doing wrong ?

Update control panel

I have a problem with the update panel. I have made this table, and in that table i have two labels ("lblResult" and "lblCheat") which i need to be updated every time the button "btnCheck" or "ImageButton1" are clicked.
When I click the next button, the whole table is updated, and it works just fine with the code i have.
I don't understand why aren't the labels updating since I am using the update panel the same way with the "btnNext" button and with the "btnCheck" and "ImageButton1"
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<center>
<asp:Label ID="lblSound" runat="server" Visible="False"></asp:Label>
<table>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Sentence: "></asp:Label></td>
<td colspan="2">
<center>
<asp:Label ID="lblSentence" runat="server" Text=""></asp:Label>
</center>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Audio: "></asp:Label>
</td>
<td colspan="2">
<audio controls="">
<source src="Sound/<%=FilePath %>" />
</audio>
</td>
</tr>
<tr>
<td style="height: 11px">
<asp:Label ID="Label1" runat="server" Text="Write the correct word: "></asp:Label>
</td>
<td style="height: 11px">
<asp:TextBox ID="txtWord" runat="server" ontextchanged="txtWord_TextChanged"></asp:TextBox>
</td>
<td style="height: 11px">
<center>
<asp:Button ID="btnCheck" runat="server" onclick="btnCheck_Click"
Text="Check" />
<asp:ImageButton ID="ImageButton1" runat="server" Height="30px"
ImageUrl="~/Besilka/Question-mark-icon.png" onclick="ImageButton1_Click"
Width="30px" />
</center>
</td>
</tr>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<tr>
<td>
<center>
<asp:Label ID="lblResult" runat="server"></asp:Label>
</center>
</td>
<td>
<center>
<asp:Label ID="lblCheat" runat="server" Text=""></asp:Label>
</center>
</td>
</tr>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnCheck" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="ImageButton1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</table>
</center>
<asp:Button ID="btnNext" runat="server" onclick="btnNext_Click" Text="Next" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnNext" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Thanks in advance!
Try setting your nested update panel UpdateMode="Conditional".
See this arcticle:
Specifically read "How UpdatePanel Controls Are Refreshed", it actually talks about UpdateMode and nesting update panels.
http://msdn.microsoft.com/en-us/library/bb386454%28v=vs.100%29.aspx
Update panels take a bit getting use to :)

Why all contents are aligned left within a content template in an update panel?

If I write dummy text in the 2 labels before the update timer starts, one appears at the right and the other appears at the left as expected
However, when the updateTimer gets into picture both texts appear on the left stuck to each other
here's the code
<table width="100%" border="0" cellspacing="7" cellpadding="0">
<tr>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer runat="server" ID="UpdateTimer" Interval="5000" OnTick="UpdateTimer_Tick" />
<asp:UpdatePanel runat="server" ID="TimedPanel" UpdateMode="Conditional" RenderMode="Inline">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateTimer" EventName="Tick" />
</Triggers>
<ContentTemplate>
<td align="left">
<asp:Label ID="userNameLabel" runat="server"></asp:Label>
</td>
<td align="right">
<asp:LinkButton ID="userWebsiteLabel" runat="server"></asp:LinkButton>
</td>
</ContentTemplate>
</asp:UpdatePanel>
</tr>
</table>
The TimedPanel is rendering as a span, like this:
<span id="TimedPanel">
<span id="userNameLabel">label</span>
<a id="userWebsiteLabel" href="javascript:__doPostBack('userWebsiteLabel','')">linkbutton</a>
</span>
Change your ContentTemplate to:
<ContentTemplate>
<asp:Label ID="userNameLabel" runat="server" Text="label" />
<asp:LinkButton ID="userWebsiteLabel" runat="server" Text="linkbutton" />
</ContentTemplate>
And add some CSS to align the LinkButton to the right:
<style type="text/css">
#TimedPanel a {float: right;}
</style>

Couldn't find updatepanel inside hidden div

I have an Updatepanel inside hidden Div, but I am getting "Could not find UpdatePanel with ID 'ctl00_ContentPlaceHolder_ctl04_UpdatePanel1'. I am trying to show and hide this panel from code behind. Thanks for any help. Here is my code.
<div id="div1" runat="server" style="display:none">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table id="Table1">
<tr>
<td>
<telerik:RadComboBox ID="RadComboBox1" runat="server"
AutoPostBack="true" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
</telerik:RadComboBox>
</td>
<td valign="top">
<asp:Button ID="button1" runat="server" OnClick="button1_Click" Text="Test1"
/><br />
<asp:Button ID="button2" runat="server" OnClick="button2_Click" Text="Test2"
/>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
you can only manipulate the the code inside the ContentTemplate from the updatepanel's postbacks, so the "div1"s display property can't be changed by the updatepanel's postbacks.
you could move the div inside the updatepanel and then it should work
I'd try this:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel runat="server" id="div1" runat="server" style="display:none">
<table id="Table1">
<tr>
<td>
<telerik:RadComboBox ID="RadComboBox1" runat="server"
AutoPostBack="true" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
</telerik:RadComboBox>
</td>
<td valign="top">
<asp:Button ID="button1" runat="server" OnClick="button1_Click" Text="Test1"
/><br />
<asp:Button ID="button2" runat="server" OnClick="button2_Click" Text="Test2"
/>
</td>
</tr>
</table>
<asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Keep in mind the client id of div1 will no longer be div1 (unless your using .net 4 in which case you can specify that it is'div1') you can fix this a variety of ways but basically you just need to add a little bit of javascript to the page that associates the actual WebControl.ClientID with 'div1'.

File Upload is not working

I'm using file upload in my site. I'm uploading word Document(Doc,Docx). Suddenly, it's not working. It is not getting the filename. It is showing empty!!! My Code is as follows:
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<table width="100%" align="center">
<tr>
<td style="height: 21px" align="center">
<span class="lbl"></span>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Button ID="btnResumedload" Text="Download Resume" runat="server" BackColor="Maroon"
ForeColor="White" Font-Bold="true" OnClick="btnResumedload_Click" Height="27px"
Width="195px" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="center">
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:Button ID="btnUploadnew" Text="Upload New" runat="server" BackColor="Maroon"
ForeColor="White" Font-Bold="true" OnClick="btnUploadnew_Click" Height="30px"
Width="198px" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="center">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:Button ID="btnDel" Height="30px" Width="198px" OnClientClick="return confirm('Are you sure?');"
BackColor="Maroon" ForeColor="White" Font-Bold="true" Text="Delete Resume" runat="server"
OnClick="btnDel_Click"></asp:Button>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="center">
<asp:Label ID="lblmsg" runat="server" Font-Bold="True" ForeColor="Red" Visible="False"
Height="17px" Width="855px"></asp:Label>
</td>
</tr>
<tr>
<td align="center">
<span class="txt">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%--<ajaxToolkit:AsyncFileUpload ID="fpResumenew" runat="server" Visible="false" />--%>
<asp:FileUpload ID="fpResumenew" runat="server" Visible="false" Width="226px" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
</span>
</td>
</tr>
<tr>
<td align="center">
</td>
</tr>
<tr>
<td style="vertical-align: top" align="center">
<%--<asp:Button ID="btnUpload" Font-Bold="true" DisabledText="Processing..." Visible="false"
Text="Upload" BackColor="Maroon" ForeColor="White" runat="server" OnClick="btnUpload_Click" />--%>
<cc1:ClickOnceButton ID="btnUpload" Font-Bold="true" DisabledText="Processing..."
Visible="false" Text="Upload" BackColor="Maroon" ForeColor="White" runat="server"
OnClick="btnUpload_Click" DisableAfterClick="True" />
</td>
</tr>
</table>
protected void btn_Click(object sender, EventArgs e)
{
string strfilename = fp.FileName.ToString();
if (fp.PostedFile.FileName.Trim().Length != 0)
{
binary = new byte[fp.PostedFile.ContentLength];
binary = fp.FileBytes;
doc = fp.FileName;
contenttype = fp.PostedFile.ContentType;
}
}
Just a sample!!!
Nothing works for me.. Problem is that I'm using three more buttons in the same page. The other buttons initializing the file upload control. So, when clicking the upload button, the file name is empty. So, I used another page for uploading the word document. Now, it is working.. !! Anyhow, I need the solution for this!! Anyone give me idea!!
Hai vaishu
FileUpload controls are not compatible with UpdatePanel when they are used to upload files as part of an asynchronous postback.
Just check the AJAX documentation. The FileUpload control is not supported inside an UpdatePanel (http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx):
or
use asp:postbacktrigger instead of asyncpostbacktrigger
<asp:updatepanel runat="server" id="UpdatePanel1">
<contenttemplate>
<asp:FileUpload runat="server" id="FileUpload1" />
<asp:button runat="server" id="ButtonSubmit" text="Postback" />
</contenttemplate>
<triggers>
<asp:postbacktrigger controlid="ButtonSubmit" />
</triggers>
</asp:updatepanel>
or
use ajax for asynchronous file upload:
http://www.asp.net/(S(fu2l2uzphr2u3u45q2dnez55))/ajax/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx
The reason that the postback trigger is not working in your case is because the FileUpload Control is set to visible=false. If you use display:none instead, the postback trigger will work.
This works just fine, I finally solved the issue... the ButtonSubmit is reload by the trigger so the page got the info from the control.
<asp:updatepanel runat="server" id="UpdatePanel1">
<contenttemplate>
<asp:FileUpload runat="server" id="FileUpload1" />
<asp:button runat="server" id="ButtonSubmit" text="Postback" />
</contenttemplate>
<triggers>
<asp:postbacktrigger controlid="ButtonSubmit" />
</triggers>
</asp:updatepanel>

Resources