.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

เรียกใช้ Response.Write("<script language=javascript>alert('---');</script>"); Options · View
F5544eEe
Posted: Tuesday, September 30, 2008 4:11:53 PM
Rank: มือสมัครเล่น
Groups: Member

Joined: 6/2/2008
Posts: 13

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; mso-bidi-font-size:14.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Cordia New"; mso-bidi-theme-font:minor-bidi;}

            if ((textboox1.Text.Length > 6) || (textboox1.Text.Length < 4))

            {

                Response.Write("<script language=javascript>alert('ความยาวต้อง 4-6 ตัวอักษรครับ !!!');</script>");

            }else ................

 

คือจาให้ตรวจว่า มีการกรอกข้อมูลขนาดถูกต้องหรือไม่  ถ้าไม่ถูกก้อจาให้แสดงข้อความเตือน

 

 

แต่ว่ามานขึ้น error ว่า

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Details: Error parsing near '<script language=jav'.

 

paedotnet
Posted: Wednesday, October 01, 2008 11:21:14 AM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 345
Location: bkk

ลองแก้โค้ดมาเป็นแบบนี้ดูนะครับ
เมื่อคลิกที่ปุ่ม Button
หน้า Default.aspx.cs

   protected void Button1_Click(object sender, EventArgs e)
    {
        if ((TextBox1.Text.Length > 6) || (TextBox1.Text.Length < 4))
        {

            ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "alert('ความยาวต้อง 4-6 ตัวอักษรครับ !!!');", true);
         }
    }

หน้า Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
            <br />
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>

ผลลัพธ์ก็สามารถที่จะใช้ updatepanel และมี alert เกิดขึ้นมาเมื่อใส่ข้อมูลไม่ตรงตามเงื่อนไขของ if  ตามรูป
 

 



[With great power comes great responsibility]
F5544eEe
Posted: Thursday, October 02, 2008 8:34:42 PM
Rank: มือสมัครเล่น
Groups: Member

Joined: 6/2/2008
Posts: 13

ขอบคุนมากๆครับ  แต่อยากทราบเหตุผลด้วยอ่ะครับว่า ทำมายมานถึง error อ่ะครับ

paedotnet
Posted: Friday, October 03, 2008 11:28:58 AM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 345
Location: bkk

updatepanel ในการทำงานจะเกี่ยวข้องกับ Asynchronous Postback นะครับดังนั้นลองศึกษาเรื่องของ Asynchronous Postback ดู



[With great power comes great responsibility]
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by