Tina_Bhole
asked on
How to make java script and update panels work together in asp.net
Hello,
In my asp.net web application, I have used java script and update panels(script manager) together. Java script functions are getting called and working fine on the web pages which don't have update panels. Where ever I have used them together, java script function does not get called.
Could someone please help.
In my asp.net web application, I have used java script and update panels(script manager) together. Java script functions are getting called and working fine on the web pages which don't have update panels. Where ever I have used them together, java script function does not get called.
Could someone please help.
ASKER
Thanks for your response ddayx10.
Please see the following code:
Please see the following code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Downloads_Manager.aspx.cs" Inherits="VA.Downloads_Manager" Title="Downloads Manager" MasterPageFile="~/Site.master" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="SM1" runat="server" EnablePageMethods="true" EnablePartialRendering="true" EnableScriptLocalization="true" EnableViewState="true"> </asp:ScriptManager>
<asp:UpdatePanel ID="UPmain" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table cellpadding="0" cellspacing="0" border="0" class="defaultpg">
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" class="productmenu5">
<tr>
<td><asp:Button Text="Upload Files" CssClass="menutb" ID="btnUpload" OnClick="ShowUpload" runat="server"/></td>
<td><asp:Button Text="Create User" CssClass="menutb" ID="btnCreateUser" OnClick="showCreateUser" runat="server" /></td>
<td><asp:Button Text="Retrieve Password" CssClass="menutb" ID="btnRetrievePassword" OnClick="showRetrievePassword" runat="server" /></td>
<td><asp:Button Text="Remove Files" CssClass="menutb" ID="btnRemoveFiles" OnClick="showRemoveFiles" runat="server" /></td>
<td><asp:Button Text="Delete Records" CssClass="menutb" ID="btnDeleteRecords" OnClick="showDeleteRecords" runat="server" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="contents">
<asp:UpdatePanel ID="UPUpload" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:PostBackTrigger ControlID="btnuploadfile"/>
</Triggers>
<ContentTemplate>
<table cellpadding="0" cellspacing="0" border="0" class="smallform1left">
<tr>
<td colspan="2" > <asp:FileUpload runat="server" CssClass="inputfile" ID="inputfile" /></td>
</tr>
<tr><td class="bottommargin">.</td></tr>
<tr>
<td class="lbl" > Description</td>
<td><asp:TextBox runat="server" ID="txtfiledesc" CssClass="txtboxextralong"></asp:TextBox></td>
</tr>
<tr><td class="bottommargin">.</td></tr>
<tr>
<td class="floatleft" colspan="2"><asp:Button runat="server" ID="btnuploadfile" Text="Upload" CssClass="btn2sml" OnClick="UploadFile" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
-------------------------------------------code behind----------------------------------------------------
protected void UploadFile(object sender, EventArgs e)
{
if (txtfiledesc.Text.Trim() != "")
{
if ((inputfile.PostedFile != null) && (inputfile.PostedFile.ContentLength > 0))
{
try
{
string fn = System.IO.Path.GetFileName(inputfile.PostedFile.FileName);
string savelocation = Server.MapPath("Downloads\\Hotfixes") + "\\" + fn;
inputfile.PostedFile.SaveAs(savelocation);
SqlConnection mySqlConnection = new SqlConnection(GlobalClass.ConnectionStr);
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand(GlobalClass.I_Uploads, mySqlConnection);
mySqlCommand.Parameters.AddWithValue("@filename", inputfile.PostedFile.FileName);
mySqlCommand.Parameters.AddWithValue("@filedesc", txtfiledesc.Text);
mySqlCommand.ExecuteNonQuery();
mySqlCommand.Dispose();
mySqlConnection.Close();
txtfiledesc.Text = "";
UPUpload.Update();
GlobalClass.JScript_Alert = "@<script language='javascript' type='text/javascript'>alert('File has been Uploaded Successfully.');</script>";
ScriptManager.RegisterStartupScript(btnuploadfile, btnuploadfile.GetType(), "fileuploadScript1", "GlobalClass.JScript_Alert", true);
}
catch (Exception exp)
{
GlobalClass.JScript_Alert = "@<script language='javascript' type='text/javascript'>alert(" + exp.Message.ToString() + ");</script>";
ScriptManager.RegisterStartupScript(this,Page.GetType(),"courseschScript1", GlobalClass.JScript_Alert,true);
}
}
}
else
{
GlobalClass.JScript_Alert = "@<script language='javascript' type='text/javascript'>alert('Please add a Description for the File being Uploaded');</script>";
ScriptManager.RegisterStartupScript(this, Page.GetType(), "courseschScript2", GlobalClass.JScript_Alert,true);
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Downloads_Manager.aspx.cs" Inherits="VA.Downloads_Manager" Title="Downloads Manager" MasterPageFile="~/Site.master" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="SM1" runat="server" EnablePageMethods="true" EnablePartialRendering="true" EnableScriptLocalization="true" EnableViewState="true"> </asp:ScriptManager>
<asp:UpdatePanel ID="UPmain" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table cellpadding="0" cellspacing="0" border="0" class="defaultpg">
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" class="productmenu5">
<tr>
<td><asp:Button Text="Upload Files" CssClass="menutb" ID="btnUpload" OnClick="ShowUpload" runat="server"/></td>
<td><asp:Button Text="Create User" CssClass="menutb" ID="btnCreateUser" OnClick="showCreateUser" runat="server" /></td>
<td><asp:Button Text="Retrieve Password" CssClass="menutb" ID="btnRetrievePassword" OnClick="showRetrievePassword" runat="server" /></td>
<td><asp:Button Text="Remove Files" CssClass="menutb" ID="btnRemoveFiles" OnClick="showRemoveFiles" runat="server" /></td>
<td><asp:Button Text="Delete Records" CssClass="menutb" ID="btnDeleteRecords" OnClick="showDeleteRecords" runat="server" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="contents">
<asp:UpdatePanel ID="UPUpload" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:PostBackTrigger ControlID="btnuploadfile"/>
</Triggers>
<ContentTemplate>
<table cellpadding="0" cellspacing="0" border="0" class="smallform1left">
<tr>
<td colspan="2" > <asp:FileUpload runat="server" CssClass="inputfile" ID="inputfile" /></td>
</tr>
<tr><td class="bottommargin">.</td></tr>
<tr>
<td class="lbl" > Description</td>
<td><asp:TextBox runat="server" ID="txtfiledesc" CssClass="txtboxextralong"></asp:TextBox></td>
</tr>
<tr><td class="bottommargin">.</td></tr>
<tr>
<td class="floatleft" colspan="2"><asp:Button runat="server" ID="btnuploadfile" Text="Upload" CssClass="btn2sml" OnClick="UploadFile" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
-------------------------------------------code behind----------------------------------------------------
protected void UploadFile(object sender, EventArgs e)
{
if (txtfiledesc.Text.Trim() != "")
{
if ((inputfile.PostedFile != null) && (inputfile.PostedFile.ContentLength > 0))
{
try
{
string fn = System.IO.Path.GetFileName(inputfile.PostedFile.FileName);
string savelocation = Server.MapPath("Downloads\\Hotfixes") + "\\" + fn;
inputfile.PostedFile.SaveAs(savelocation);
SqlConnection mySqlConnection = new SqlConnection(GlobalClass.ConnectionStr);
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand(GlobalClass.I_Uploads, mySqlConnection);
mySqlCommand.Parameters.AddWithValue("@filename", inputfile.PostedFile.FileName);
mySqlCommand.Parameters.AddWithValue("@filedesc", txtfiledesc.Text);
mySqlCommand.ExecuteNonQuery();
mySqlCommand.Dispose();
mySqlConnection.Close();
txtfiledesc.Text = "";
UPUpload.Update();
GlobalClass.JScript_Alert = "@<script language='javascript' type='text/javascript'>alert('File has been Uploaded Successfully.');</script>";
ScriptManager.RegisterStartupScript(btnuploadfile, btnuploadfile.GetType(), "fileuploadScript1", "GlobalClass.JScript_Alert", true);
}
catch (Exception exp)
{
GlobalClass.JScript_Alert = "@<script language='javascript' type='text/javascript'>alert(" + exp.Message.ToString() + ");</script>";
ScriptManager.RegisterStartupScript(this,Page.GetType(),"courseschScript1", GlobalClass.JScript_Alert,true);
}
}
}
else
{
GlobalClass.JScript_Alert = "@<script language='javascript' type='text/javascript'>alert('Please add a Description for the File being Uploaded');</script>";
ScriptManager.RegisterStartupScript(this, Page.GetType(), "courseschScript2", GlobalClass.JScript_Alert,true);
}
}
OK I see what's wrong. I have to do something else first then I'll come back and explain in about 1/2 hour :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
WOW!!! thank you so much. It's working now :)
ASKER
The explanation was excellent. Thank you very much
YW :)
You need to show some code, and example of the type of operations involved and code that is breaking for us to be any help to you here. Please try to set it up in such a way as we have all the information to make it duplicatable.