asp:button works locally but no on server - c#

I have 4 asp:buttons on my web page. One of them works correctly the other three do not. The form on my web page is a simple encryption application. I am new to asp.net so any help would be greatly appreciated. The entire site works correctly locally of course but when uploaded on to the server 3 buttons don't work. I might be over looking something obvious but the sample code is below:
*Only the Encrypt button works.
Generic error code for other buttons:
ScriptResource.axd:5 Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Enter Password: <asp:TextBox ID="TextBox1" MaxLength="15" CssClass="Password" runat="server"></asp:TextBox>
<asp:FileUpload ID="FileUpload1" CssClass="Button" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Upload File" CssClass="Button" CausesValidation="False" onclick="Button1_Click" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<br />
Enter Text:
<br />
<asp:TextBox ID="TextBox2" TextMode="MultiLine" CssClass="TestStyle" runat="server"></asp:TextBox>
<br />
<%--<asp:TextBox ID="TextBox2" TextMode="MultiLine" CssClass="TestStyle" runat="server"></asp:TextBox>
<br />--%>
<asp:Button ID="Encrypt" OnClick="EncryptBT_Click" runat="server" CssClass="Button" CausesValidation="False" Text="Encrypt"></asp:Button>
<asp:Button ID="Decrypt" OnClick="DecryptBT_Click" runat="server" CssClass="Button" CausesValidation="False" Text="Decrypt"></asp:Button>
<fieldset>
<legend>Save Encrypted Text File</legend>File name:
<asp:TextBox ID="textboxName" runat="server" Width="93px"></asp:TextBox>
<asp:Button ID="buttonSave" runat="server" Text="Save As" CssClass="Button" Width="66px" OnClick="Save_Click" /></fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</form>

Check using developer Tools whether buttons are on the page or not.
Also, check whether their onClick method has been implemented or not in code -behind.

Related

Code behind getting Null Value of Asp.net File upload control inside Update Panel using Asp.net C#

Code behind getting file upload value is null and inside the update panel using file upload. I also used Triggers tag but I'm getting an error when submitting
ERROR:Object reference not set to an instance of an object.
And also debug but getting a null value of File uploader in code behind. Also, I check for (!IsPostBack) property in page load.
<asp:UpdatePanel ID="UpdatePanel9" runat="server" UpdateMode="Conditional">
<Triggers><%--
<asp:PostBackTrigger ControlID="lnkbtn_Update_HostScientistLetter_Edit" />
<asp:AsyncPostBackTrigger ControlID="lnkbtn_Update_HostScientistLetter_Edit"/>--%>
<asp:AsyncPostBackTrigger ControlID="lnkbtn_Update_HostScientistLetter_Edit" />
</Triggers>
<ContentTemplate>
<div class="col-xs-6">
<div class="form-group">
<div class="form-field">
<label class="control-label">Host Scientist Letter</label>
<br />
<div class="table-responsive">
<asp:FileUpload ID="FileUpload_HostScientistLetter_Edit" runat="server" CssClass="form-control" Visible="false" />
<asp:Label ID="lbl_file_error1" runat="server" ForeColor="Red"></asp:Label>
<asp:LinkButton ID="lnkbtn_HostScientistLetter_Edit_update" runat="server" OnClick="lnkbtn_HostScientistLetter_Edit_update_Click" Visible="true"></asp:LinkButton>
<asp:LinkButton ID="lnkbtn_change_HostScientistLetter_Edit" ForeColor="#21a04f" runat="server" Text="Click Here to upload new file" OnClick="lnkbtn_change_HostScientistLetter_Edit_Click"></asp:LinkButton>
<asp:LinkButton ID="lnkbtn_Update_HostScientistLetter_Edit" ForeColor="#21a04f" runat="server" Text="Update" OnClick="lnkbtn_Update_HostScientistLetter_Edit_Click" Visible="false" ValidationGroup="HostScientistLetter"></asp:LinkButton>
<asp:LinkButton ID="lnkbtn_Cancel_HostScientistLetter_Edit" ForeColor="#21a04f" runat="server" Text="Cancel" OnClick="lnkbtn_Cancel_HostScientistLetter_Edit_Click" Visible="false"></asp:LinkButton>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" Display="Dynamic" runat="server" ErrorMessage="Upload Host Scientist Letter" ControlToValidate="FileUpload_HostScientistLetter_Edit" ValidationGroup="HostScientistLetter" CssClass="err-msg"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator8" Display="Dynamic" runat="server" ErrorMessage="Only .pdf,.doc,.docx,.ppt files are allowed." ValidationExpression="^.*\.(PDF|pdf|doc|docx|DOC|DOCX)$" CssClass="err-
msg" ValidationGroup="HostScientistLetter" ControlToValidate="FileUpload_HostScientistLetter_Edit"></asp:RegularExpressionValidator>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>

ModalPopupExtender calling .Show() does not work

I am using Visual Studio 2010 and for database I am using Entity Framework 4.
In my page , I have 3 tabs and in Second tab I used Grid view for displaying the Details of Employee . In that Grid View there are 2 image button one for Delete another for Edit. I want to open a popup box whenever I will click Edit Image Button.
The problems are
1. Popup box is appear for a second only.
2. Able to retrieve the row index of the Grid view. But no value is pass into other text box, it showing null value i.e. name0.Text= ""
In my .aspx page I have the following
For Image Button
<asp:ImageButton ID="edit" runat="server" CommandArgument='<%# Bind("EmpID")%>' CommandName="edituser" ImageUrl="image/images.jpg" ToolTip="Edit User Details" OnClick="EditUser_Clicked"> </asp:ImageButton>
For ModalPopupExtender
<asp:ToolkitScriptManager ID="Toolkitmgr" runat="server"></asp:ToolkitScriptManager>
<asp:HiddenField ID="EmpID" runat="server"
onvaluechanged="EmpID_ValueChanged"/>
<asp:ModalPopupExtender ID="mpedit" DropShadow="true" BackgroundCssClass="modalBackground"
PopupControlID="pnedit" CancelControlID="btnCancel"
runat="server" TargetControlID="EmpID"></asp:ModalPopupExtender>
<asp:Panel runat="server" ID="pnedit" CssClass="modalPopup" Style="display: block;width:525px">
***Some Code***
</asp:Panel>
In the server side code for the EditUser_Clicked event I have the following:
protected void EditUser_Clicked(object sender, EventArgs e)
{
ImageButton btndetails = sender as ImageButton;
GridViewRow row = (GridViewRow)btndetails.NamingContainer;
lblId.Text = GridView1.DataKeys[row.RowIndex].Value.ToString();
name0.Text = row.Cells[1].Text;
desig0.Text = row.Cells[2].Text;
dob0.Text = row.Cells[3].Text;
email0.Text = row.Cells[4].Text;
country0.Text = row.Cells[5].Text;
city0.Text = row.Cells[6].Text;
add0.Text = row.Cells[7].Text;
hq0.Text = row.Cells[8].Text;
rbtnListGender0.Text = row.Cells[9].Text;
mobno0.Text = row.Cells[10].Text;
this.mpedit.Show();
}
The code runs without error but modal popup is not visible. Please help me to find my mistake.
There 3 ways You can use Modal Popup using Update Panel.Try any one of this.
Modal Popup with UpdatePanel inside PopupPanel
<div style="background-color: White">
<asp:Button runat="server" ID="button4" Text="Launch Modal Popup1" />
<asp:Panel runat="server" ID="modalPanel3" Style="display: none">
<asp:UpdatePanel runat="server" ID="updatePanel3">
<ContentTemplate>
<asp:Label runat="server" ID="label4" Text="Label in UpdatePanel"></asp:Label>
<asp:Button runat="server" ID="Button5" Text="Click to Cause postback" OnClick="Button5_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button runat="server" ID="Button6" Text="OK" />
<asp:LinkButton runat="server" ID="LinkButton1" Text="Cancel" />
</asp:Panel>
<ajaxToolkit:ModalPopupExtender runat="server" ID="modalPopupExtender3" TargetControlID="button4"
PopupControlID="modalPanel3" OkControlID="Button6" CancelControlID="LinkButton1"
BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
</div>
2.Update Panel that contains a ModalPopup and its associated PopupPanel inside it
<asp:UpdatePanel runat="server" ID="updatePanel2" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Button runat="server" ID="button2" Text="Launch Modal Popup2" />
<asp:Panel runat="server" ID="modalPanel2" BackColor="AliceBlue" Style="display: none">
<asp:Label runat="server" ID="label5" Text="Label in UpdatePanel"></asp:Label>
<asp:Button runat="server" ID="postbackBtn" Text="Click to Cause postback" OnClick="postbackBtn_Click" /><br />
<asp:Button runat="server" ID="cancelBtn2" Text="OK" />
<asp:LinkButton runat="server" ID="okBtn2" Text="Cancel" />
</asp:Panel>
<ajaxToolkit:ModalPopupExtender runat="server" ID="modalPopupExtender2" TargetControlID="button2"
PopupControlID="modalPanel2" OkControlID="okBtn2" CancelControlID="cancelBtn2"
BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
3.Update Panel that contains a ModalPopup; its PopupPanel has an UpdatePanel inside it
<asp:UpdatePanel runat="server" ID="outerUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="false">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="outerPanelTrigger" />
</Triggers>
<ContentTemplate>
<asp:Button runat="server" ID="outerPanelTrigger" Text="OuterPanelTrigger" /><br />
<br />
<asp:Button runat="server" ID="button1" Text="Launch Modal Popup3" />
<asp:Panel runat="server" ID="modalPanel1" BackColor="Pink" Style="display: none">
<asp:UpdatePanel runat="server" ID="updatePanel1" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="label1" Text="Label in UpdatePanel"></asp:Label>
<asp:Button runat="server" ID="updateLabel" OnClick="updateLabel_Click" Text="Click to Cause postback" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button runat="server" ID="okBtn" Text="OK" />
<asp:LinkButton runat="server" ID="cancelBtn" Text="Cancel" />
</asp:Panel>
<ajaxToolkit:ModalPopupExtender runat="server" ID="modalPopupExtender1" TargetControlID="button1"
PopupControlID="modalPanel1" OkControlID="okBtn" CancelControlID="cancelBtn"
BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
Are you using the latest version of AjaxControlToolkit?
In v16.1 the following bugs were fixed:
Item 27971 - Modal Popup incorrect z-index in tab container and
update panel
Item 28021 - Multiple ModalPopupExtenders z-index
issue

C# Infinite Nested DataList

I have a relatively simple question about nested DataList.
How to dynamically nest infinite DataLists?
I didn't write any code yet, because I don't know how, but follow is an example:
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<asp:DataList ID="DataList2" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button2" runat="server" Text="Button" />
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
</form>
There are no problems when we have limited levels depth, we just nest two or three levels on DataList and we are done. But when we don't have a defined levels depth.
When the button clicked it loads the DataList2, when DataList2 button is clicked and it should load DataList3 and so far. And repeat it every time I click the button inside a DataList.
e.g.
-DatalistOUTER
--Some bindings
--Button [clicked]
[loads]
----DatalistINNER
-----Some bindings
-----Button [clicked]
[loads]
------DatalistINNERINNER
-------Somebindings
-------Button

Update Progress on processing after fileupload

I have a webform with two upload controls and a number of textfields.
When the button is pressed the files get uploaded and then get processed.
The upload takes no time, but the processing does.
I know I can't have an upload control in an update panel, so I can't work out how to use the update progress control to show my progress.
My page with an updateprogress control that does work is as follows:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DynamicLayout="true">
<ProgressTemplate>
<div class="LOADING">
Your data is being processed<br />
<br />
<img src="/images/loading.gif" /><br />
<br />
Please wait...
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<div class="addFixture">
<asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="fixture" runat="server" />
<label>
Type
<asp:DropDownList ID="ddlType" runat="server" AppendDataBoundItems="true">
<asp:ListItem Text=""></asp:ListItem>
</asp:DropDownList>
<label>
Date
</label>
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
<label>
Name 1</label>
<asp:TextBox ID="txtName1" runat="server"></asp:TextBox>
<label>
Name 2
<asp:TextBox ID="txtName2" runat="server"></asp:TextBox>
<label>
First XML File</label>
<asp:FileUpload ID="firstFileUp" runat="server" />
<br />
<label>
Second Xml File</label>
<asp:FileUpload ID="secondFileUp" runat="server" />
<br />
<br />
<asp:Button ID="SubmitButton" runat="server" CausesValidation="true" Text="Submit" OnClick="SubmitButton_Click" />
<asp:Label ID="ErrorMessageLabel" runat="server" EnableTheming="false"></asp:Label>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I have searched for this, but people seem to be trying to get the progress of the file upload and not the processing.
Can anyone help?
Remove the UpdatePanel as all the way you can't use FileUpload controls inside it.
Add to the SubmitButton OnClientClick property with following value: OnClientClick="showProgress()"
Also add onto the page javascript function below:
function showProgress() {
var updateProgress = $get("<%= UpdateProgress1.ClientID %>");
updateProgress.style.display = "block";
}
By the way, consider to use some async file upload control like one from the Ajax Control Toolkit library
You can use an UpdatePanel and the FileUpload if you use the ASyncFileUploadControl. It works pretty well. Make sure you download the latest version because there were a couple of issues with prior releases.

triggered button cause fullpostback

I've got an updatePanel and a button which triggered in it.
However, the button causes full postback instead of partial one.
Here's my Code:
<asp:Button ID="cEvent" runat="server" Text="צור יום" Width="80px"
Height="40px" Font-Size="Medium" onclick="cEvent_Click" CausesValidation="false"/>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel id = "updatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cEvent" EventName="Click"/>
</Triggers>
<ContentTemplate>
<div id="yesEve" runat="server" visible="false" style="width:95%; float:right; margin-left:5%; padding-top:20px; margin-bottom:20px;">
<table id="mytable" cellspacing="0" runat="server">
</table>
</div>
<div id="errorMsg" runat="server" visible="false" style="width:100%; text-align:center; float:right;">
<asp:label visible="true" ID="msg1" Font-Size="Medium" runat="server" Font-Bold="true" Text = "היום נמחק בהצלחה"></asp:label>
</div>
<div id="noEve" style="width:100%; padding-top:20px; float:right; text-align:center; margin-bottom:20px;" runat="server" visible="false">
<asp:label visible="true" ID="stamLabel" Font-Size="Medium" runat="server" Font-Bold="true" Text = "לא קיימים ימים פתוחים"></asp:label>
</div>
<asp:LinkButton ID ="remove" runat="server"></asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
I really need some help with that... i'm searching for hours all over the web to find an answer.
Thanks, Matan
In the code behind, you can try adding this line:
ScriptManager.GetCurrent(Page).RegisterPostBackControl(Button1);
There is nothing wrong with your code, you have a conflict somewhere with code(ClientIDs) you haven't show us or a JavaScript error breaking the page.
Here's a template for how to do this from a microsoft tutorial page:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel</legend>
<asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br />
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
More information here:
microsoft tutorial

Categories