I have this problem which i cannot seem to understand...
i have a master page and an image control on it....it is a social networking website and then i have a content page..there is a link button on the master page when when clicked shows a modal popup which has a fileupload control and a user can submit an image file...when he does so the image get saved in a directory and also its complete address is saved in the database...
now 2 problems...
after committing these actions (on the master page code file ) i set the image url to the saved path (in a temporary string, which gets tored in the database) but the image doesnt show...it has been saved in the directory so why????
and the second one...say we forget this first problem...the image is in the directory and the path is in the database....so on page load of content page i find the master page Image control and set its image url to the value form DB but it still doesnt show...
why this happens i have no idea....plz guys if i am missing something please let me know...
code on master page......vb file
snippet for server click event of ok button on MODAL POPUPTry con.Open() trans = con.BeginTransaction(IsolationLevel.ReadCommitted) Dim s As String = "update general set upimg_1='" & finalPath & "' where user_id='" & userID & "'" MsgBox(s) cmd = New OleDbCommand(s, con, trans) 'attempt to save the file
Image1.ImageUrl = finalPath
Catch ex As Exception
MsgBox("An error has occured,please try again later" & ex.Message)
Finally con.Close()and for the content page...Sub setProfilePic()
cmd = New OleDbCommand("select upimg_1 from general where user_id='" & Session("user_id") & "'", con) Dim reader As OleDbDataReader con.Open() reader = cmd.ExecuteReader() reader.Read() If reader.HasRows Then Dim img As Image img = CType(Master.FindControl("Image1"), Image)
img.ImageUrl = reader("upimg_1").ToString()
End If con.Close()in debugging mode i have searched and it finds this image control and its imageurl is set the value from db but it still doesnt show...plz help guys....what am i doing wrong here
I've made a small test now with a image control on the master page and a function in the content page that set's the image url and it works fine.
Maybe try hardcoding a value instead of setting it to your reader's value, just to test.
If it works then it might not be resolving the value of your reader correctly.
PS: Make sure the image is actually there and relative to your page calling it.
Programming - You're doing it all wrong..
i did the same test and it worked as well and thanx to that i have found the real problem...
i was resizing the image before saving it using Image and graphics classes and then save it....noew these images can be viewed in MS PAINT and Windows Picture and Fax Viewer but the Image control cannot display them
when set to other pictures in the directory it works well.....
tried the image button but it cannot show it as well.....so i think i will change my code to resize the images
i will post this code in an appropriate thread..
i dont know if any of you have encountered this but
in my above posted code if i manually set the path as
Dim img As Image img = CType(Master.FindControl("Image1"), Image) img.ImageUrl = "D:\websites\sandesh4u\userImages\community\1_PANKAJ.jpg"then it shows the imagebut when set tocmd = New OleDbCommand("select upimg_1 from general where user_id='" & Session("user_id") & "'", con) Dim reader As OleDbDataReader con.Open() reader = cmd.ExecuteReader() reader.Read() If reader.HasRows Then Dim img As Image img = CType(Master.FindControl("Image1"), Image)
'img.ImageUrl = "D:\websites\sandesh4u\userImages\community\1_PANKAJ.jpg" Dim s As String s = reader("upimg_1").ToString()
img.ImageUrl = s
End If con.Close()it doesnt work...now what is the problem??? has anyone faced this issue??
i figured it out...
i was really being stupid because i wasnt using trim() when storeing it in the database and recieving it
sorry for all the trouble...
moral of the story : ALWAYS USE TRIM WHEN HANDLING STRING STORAGE IN DATABASE
Glad you got it... I thought you might also maybe want to use "ResolveUrl" on your reader value.
Programming - You're doing it all wrong..