In my application, When the user clciks a button,some coding wil run, after that a popup window should appear, with a image button and its saved to sql server.

I am using asp.net 2.0

Plz help me

Dani AI

Generated

Short, practical plan that complements the replies from , , and .

Pick the UI pattern first: an in-page modal (AJAX modal) gives the best UX and avoids popup blockers; a new browser window is simpler but can be blocked. The usual flow is: do your server-side work on the button click, then tell the browser to show the popup containing the ImageButton. If you use partial postbacks (UpdatePanel) use ScriptManager.RegisterStartupScript so the client script runs after the partial postback; for a full postback you can emit a startup script. pointed toward AJAX/ModalPopup for a smooth UI, demonstrated emitting client script, and showed simple client-side testing techniques.

A few concrete implementation notes:

  • Put the ImageButton inside the modal. It can either cause a server postback (server-side Click handler) or call an AJAX endpoint (PageMethod/ASHX/WebMethod) to send image bytes for saving.
  • If you accept file uploads, remember standard FileUpload does a full postback; to upload during AJAX you need an iframe/async uploader or a toolkit control.
  • For DB storage prefer either storing files on disk/cloud and saving a path, or store bytes in a varbinary(MAX) column for smaller volumes.

Example save pattern (ADO.NET):

/* table example:
   CREATE TABLE Images (
     Id INT IDENTITY PRIMARY KEY,
     FileName NVARCHAR(255),
     Content VARBINARY(MAX),
     ContentType NVARCHAR(100),
     Created DATETIME
   );
*/

byte[] bytes;
using (var ms = new MemoryStream(fileUpload.PostedFile.InputStream))
{
    bytes = ms.ToArray();
}

using (var cn = new SqlConnection(connString))
using (var cmd = new SqlCommand(
  "INSERT INTO Images (FileName, Content, ContentType, Created) VALUES (@fn,@content,@type,@dt)", cn))
{
    cmd.Parameters.Add("@fn", SqlDbType.NVarChar, 255).Value = fileName;
    cmd.Parameters.Add("@content", SqlDbType.VarBinary, -1).Value = bytes;
    cmd.Parameters.Add("@type", SqlDbType.NVarChar, 100).Value = contentType;
    cmd.Parameters.Add("@dt", SqlDbType.DateTime).Value = DateTime.UtcNow;
    cn.Open();
    cmd.ExecuteNonQuery();
}

Quick troubleshooting: popup blockers, cross-window JavaScript restrictions, UpdatePanel vs file-upload limitations, and web.config maxRequestLength (default 4096 KB) for large files.

Recommended Answers

All 3 Replies

Hi Anusha,

You can run the code asynchronously using ajax and initiate a ModalPopUp which will pop up with your requirement (image or anything you want) after running the code. Hope this helps.

Thanks

You can use Page.ClientScript.RegisterStartupScript to open a popup window from ASP.NET code behind. For example

protected void LinkButton1_Click(object sender, EventArgs e)
    {

       //Write some code here


        string url = "TestPage2.aspx";
        ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", url));

    }

for pop up in asp.net

%>
<SCRIPT LANGUAGE="Javascript">
alert("<%  = strMessageToShow %>")
</SCRIPT>
<%
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.