Click here to Skip to main content
16,011,784 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am sending image path(as image save in folder) from web service like

[System.Web.Services.WebMethod(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string GetDynamicContent(string contextKey)
{
string constr = "Data Source=Subhasish-PC;Initial Catalog=testabhijit;Integrated Security=SSPI;";
string query = "SELECT ImagePath FROM imagetable WHERE id = " + contextKey;


SqlDataAdapter da = new SqlDataAdapter(query, constr);
DataTable table = new DataTable();

da.Fill(table);
string x = table.Rows[0]["ImagePath"].ToString();


return x.ToString();

}

Now at .aspx page i am taking panel and image control, like below

<asp:Panel runat="server" CssClass="modalPopup" ID="panSaving" Style="display: none">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<asp:Image ID="imgClose" runat="server" ImageUrl='' Height="336" Width="430"/>
</td>
</tr>

</table>
</asp:Panel>

My problem is how i will bind ImageUrl of image control......so that which path is sending at web service i can access. Thank you.
Posted

1 solution

Hi Rohit,

You can do this by calling that webservice through javascript.

Below is the code snippet.

First you have to enable PageMethods using scriptmanager
<asp:scriptmanager id="ScriptManager1" runat="server" enablepagemethods="true" xmlns:asp="#unknown">


then write a javascript function to call the webservice



fubction Test(contextKey)
{
PageMethods.GetDynamicContent(contextKey,
OnSucceeded, OnFailed);
}
function OnSucceeded() {
// Dispaly "thank you."
// write javascript code to bind image path
//var img=document.getElementById(ur image id);
}
function OnFailed(error) {
// Alert user to the error.
alert(error.get_message());
}

Hope this helps
 
Share this answer
 
Comments
Rohit Sharma706 17-Nov-11 2:18am    
First of all Thanx...i try with these..like these....
function Test(contextKey)
{
PageMethods.GetDynamicContent(contextKey,
OnSucceeded, OnFailed);
}
function OnSucceeded() {
// Dispaly "thank you."
// write javascript code to bind image path
// var img = document.getElementById("imgClose");
// img.ImageUrl=x.tostring()
//alert("Thank u")
}
function OnFailed(error) {
// Alert user to the error.
alert(error.get_message());
}
....
var img = document.getElementById("imgClose");
img.ImageUrl=x.tostring().....is it have some problem in these two line. Thank You.
Rohit Sharma706 17-Nov-11 2:20am    
Like these also i check...
var img = document.getElementById(imgClose)
img.ImageUrl=x.tostring().....is it have some problem in these two line. Thank You.
Rohit Sharma706 17-Nov-11 2:30am    
at
<asp:ScriptManager ID="ScriptManager1" runat="server" enablepagemethods="true" xmlns:asp="#unknown">
it showing these error...
Parser Error Message: Type 'System.Web.UI.ScriptManager' does not have a public property named 'xmlns:asp'.
so i try with this
<asp:ScriptManager ID="ScriptManager1" runat="server" enablepagemethods="true">

but popup image not display... if i do wrong at..
var img = document.getElementById(imgClose)
img.ImageUrl=x.tostring()
Thank you.
Rohit Sharma706 17-Nov-11 2:58am    
My .aspx page Form section like these...
<form id="form1" runat="server">
<div>



<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" enablepagemethods="true">

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<columns> <asp:BoundField DataField="id" HeaderText="Image ID" />
<asp:TemplateField>
<itemtemplate>
<asp:ImageButton ID="imgBtnTour" runat="server" ImageUrl='<%#DataBinder.Eval(Container.DataItem,"ImagePath") %>' Width="80" OnClientClick="return ShowPopup();"/>




<asp:Button runat="server" ID="btnHiddenPopUp" Style="display: none" />

<asp:ModalPopupExtender ID="mpeTest" runat="server" TargetControlID="btnHiddenPopUp"
PopupControlID="panSaving" BackgroundCssClass="modalBackground" DropShadow="true"
RepositionMode="RepositionOnWindowResize" CancelControlID="imgClose" DynamicServiceMethod="GetDynamicContent" DynamicContextKey='<%# Eval("id") %>' DynamicControlID="imgClose"/>


<asp:Panel runat="server" CssClass="modalPopup" ID="panSaving" Style="display: none">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<asp:Image ID="imgClose" runat="server" ImageUrl='pics/Koala.jpg' Height="336" Width="430"/>
</td>
</tr>

</table>

</div>
</form>
....
script section like these...
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function ShowPopup() {

//show modal popup window
var modalWindow = '<%= mpeTest.ClientID %>';
$find(modalWindow).show();

//add event handler to hide the modal popup when user click background of the popup window
var backgroundElement = $get(modalWindow + '_backgroundElement');
if (backgroundElement) $addHandler(backgroundElement, 'click', hideModalPopupViaClient);

return false;
}

function hideModalPopupViaClient() {

//hide modal popup window
var modalPopupBehavior = $find('<%= mpeTest.ClientID %>');

if (modalPopupBehavior) {
modalPopupBehavior.hide();
}
}
function Test(contextKey) {
PageMethods.GetDynamicContent(contextKey,
OnSucceeded, OnFailed);
}
function OnSucceeded() {
// Dispaly "thank you."
// write javascript code to bind image path
var img = document.getElementById[imgClose];
img.src = x;

//alert("Thank u")
}
function OnFailed(error) {
// Alert user to the error.
alert(error.get_message());
}

</script>
......
Rohit Sharma706 17-Nov-11 3:01am    
code behind web service part like these....
[System.Web.Services.WebMethod(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string GetDynamicContent(string contextKey)
{
string constr = "connection string";
string query = "SELECT ImagePath FROM imagetable WHERE id = " + contextKey;


SqlDataAdapter da = new SqlDataAdapter(query, constr);
DataTable table = new DataTable();

da.Fill(table);
string x = table.Rows[0]["ImagePath"].ToString();
return x.ToString();

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900