Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET Update Panell - RegisterStartupScript doesn't seem to work

Status
Not open for further replies.

fletchsod

Programmer
Dec 16, 2002
181
Hi! I noticed this doesn't work and I'm a little puzzled on how to make this work. The javascript alert() should work but it doesn't... So, is there a way to make this work? Thanks...

//Aspx webpage
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Admin33.aspx.cs" Inherits="Admin1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head runat="server">
 <title></title>
</head>
<body>
    <form id="form1" runat="server">
    
        <!-- ASP.NET AJAX Script Only... -->
        <asp:ScriptManager ID="ScriptManager1" runat="server" />

        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
            
              <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                <ContentTemplate>

		          <div style="display:table-cell;">
		            <table border="0" cellpadding="0" cellspacing="2" align="left">
		             <tr>
		              <td>
		                 Zip Code: &nbsp;
		              </td>
		              <td>
			            <asp:textbox id="txtSearchZipCode" Width="80px" runat="server"></asp:textbox>
			            &nbsp;&nbsp;
                        <asp:button id="btnZipDecode" Height="24px" Text="Update" runat="server" OnClick="btnZipDecode_ServerClick"></asp:button>
		              </td>
		             </tr>
		            </table>
		          </div>
		      
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnZipDecode" EventName="Click" />
                </Triggers>
              </asp:UpdatePanel>
            
            </ContentTemplate>
            <Triggers>
            </Triggers>
        </asp:UpdatePanel>
        
    </form>
</body>
</html>

//CodeBehind
Code:
public partial class Admin1 : System.Web.UI.Page
{
    protected void btnZipDecode_ServerClick(object sender, EventArgs e)
    {
        try
        {
            //Initialize variables...
            string sJavaScriptErrorMsg = "";

            //Enforce the zipcode validation...
            if (Convert.ToString(this.txtSearchZipCode.Text).Trim().Length == 0)
            {
                sJavaScriptErrorMsg = "";
                sJavaScriptErrorMsg += "Zip is required!!";

                this.txtSearchZipCode.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffcc66");
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.UpdatePanel1.GetType(), System.Guid.NewGuid().ToString(), "alert('" + sJavaScriptErrorMsg + "');", true);
                return; //This exit the function...
            }
        }
        catch (Exception ex)
        {
            Response.Write("Error!!!!");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //Clear the textbox's/drop-down's/combo's textbox selection...
            this.txtSearchZipCode.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");

            if (Page.IsPostBack == false) {
                //Get ZipCode...
                this.txtSearchZipCode.Text = "";
            }
        }
        catch (Exception ex)
        {
            Response.Write("Error!!!!");
        }
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top